Either is a type used in functional languages such as Haskell and Scala to represent a value that is one of two parametrized types. In Scala, the Either type is often used as an alternative to scala.Option where Left represents failure (by convention) and Right is akin to Some.
Questions tagged [either]
341 questions
0
votes
1 answer
ADT vs Either vs Exceptions
So, the current implementation uses twitter's Future along with throwing exceptions to signal invalid use-case along with for-comprehensions, like so:
def someMethod(a: ...): Future[X] = {
// do something
// if something goes wrong throw…

iyerland
- 632
- 2
- 10
- 24
0
votes
1 answer
Custom spray json format of Either[TimeSlot,DateSlot] stuck in some kind of type-inference loop
My spray json serialization does not seem to work, as my tests just keeps running, when i am trying to serialize an Either[TimeSlot, DateSlot] object to JsValue, and vice-versa when i am trying to parse a json string and convert it to…

szeigo
- 1
- 2
0
votes
0 answers
Scala - Understanding folds on an Either type
I am trying to understand a fold example.
val rowStream: Stream[IO, Rows] = ...
rowStream.fold(Right(()): Either[RowError, Unit]) {
case (Right(_), b) =>
// completely succeed here
//b.rows... etc
case (Left(_), _) =>
…

Chris
- 785
- 10
- 24
0
votes
1 answer
Scala : Expression of Type None. Type doesn't confirm to expect type Document
I am new to Scala coding. I have below code snippet which builds document using documentBuilder. My input is XML. Whenever I input an malformed XML below code is failing to parse and raising SAXException.
def parse_xml(xmlString: String)(implicit…

user2531569
- 609
- 4
- 18
- 36
0
votes
1 answer
languageext eitherasyn with aggegrate bind with validation
I am using lauthy language ext in c# here are 3 functions those will be called in form main function
the aim is return aggregated results of commands.. or Error but it is complinign below when I pass y to ExecuteSingleHostCommands
Error CS1503 …

userkk
- 3
- 2
0
votes
1 answer
Haskell function with Either input
I can't seem to write a simple haskell function that gets an Either input and use it. Here is what I wrote:
$ cat main.hs
module Main( main ) where
-- myAtoi :: Either String Int -> Int
myAtoi :: Int -> Int
myAtoi _ = 700
main :: IO ()
main =…

OrenIshShalom
- 5,974
- 9
- 37
- 87
0
votes
2 answers
Using Either in a lookup where no key exists in Haskell
I'm following along with this:
https://www.schoolofhaskell.com/school/starting-with-haskell/basics-of-haskell/10_Error_Handling#either-may-be-better-than-maybe
And I am trying to get a column of data from a CSV by variable name in the headers,…

Mittenchops
- 18,633
- 33
- 128
- 246
0
votes
1 answer
List[EitherT[Future, String, CustomObj]] => EitherT[Future, String, List[CustomObj]]
How to use sequence function for List[EitherT[Future, String, CustomObj]] with custom class CustomObj ? I want something like that :
import scala.language.postfixOps
import cats.instances.list._
import cats.syntax.traverse._
import…

Dex
- 13
- 2
0
votes
2 answers
Scala - Is there a function to map Seq[A] => Seq[Either[Throwable, B]]?
I am looking for a function that will map over a collection coll: Seq[A] while applying a function f: A => B and returning a Seq[Either[Throwable, B]] so that errors can be handled downstream.
Is there a function similar to this that is pre-baked…

D Cohen
- 157
- 1
- 7
0
votes
1 answer
Haskell - Continuing to next do after validating with either
I'm new to Haskell and using do notation to validate a user's choice with an Either.
userChoice :: String -> Either String String
userChoice option
| option == "1" = Right "You proceed with option 1."
| option == "2" = Right "You proceed…

Jamin
- 1,362
- 8
- 22
0
votes
2 answers
Traversing Either in Scala
I wrote the following simple code:
import cats.effect.IO
import cats.instances.either._
import cats.syntax.TraverseSyntax
object Test extends App with TraverseSyntax{
val e: Either[String, IO[Int]] = Right(IO(2))
e.sequence //error…

St.Antario
- 26,175
- 41
- 130
- 318
0
votes
1 answer
Scala Either with List
I wanted to implement a similar type called Result to the Either type. The main difference is, that the Left side of the Result type should always be a List of something. What would be the right type definition for this? I tried having something…

Lando-L
- 843
- 6
- 19
0
votes
3 answers
Break loop if Either function returns Left
In the following code, what I need is to stop processing the loop if either either1 or either2 return Left, and if that happens then mainFunction has to return Left as well. Also, the string returned by either1.Left or either2.Left needs to be…

ps0604
- 1,227
- 23
- 133
- 330
0
votes
1 answer
Passing through Left statement in Either
Given these two methods that use Either, in the second method I need to forward the error using Left(error) => Left(error). Is there a way to omit this in the second method (or use more elegant code) as the statement just needs to be passed through?…

ps0604
- 1,227
- 23
- 133
- 330
0
votes
1 answer
How to disregard a standard module?
As an exercise, I am trying to implement my own version of a standard Functor, in this case Either.
My code looks similar to the standard definition:
instance Functor (Either a) where
fmap _ (Left x) = Left x
fmap f (Right y) = Right (f y)
When…

mherzl
- 5,624
- 6
- 34
- 75