Questions tagged [either]

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.

341 questions
0
votes
1 answer

Scala - Recursive Patten Matching Using Either

I currently have something that looks like this: data foreach { case Left(Left(Left(Left(Left(Left(Left(Left(Left(Left(Left(Left(Left(Left(Left(Left(Left(Left(Left(a))))))))))))))))))) => /* Do something */ case…
Olshansky
  • 5,904
  • 8
  • 32
  • 47
0
votes
4 answers

Haskell - Maybe Either

-- | Convert a 'Maybe a' to an equivalent 'Either () a'. Should be inverse -- to 'eitherUnitToMaybe'. maybeToEitherUnit :: Maybe a -> Either () a maybeToEitherUnit a = error "Not yet implemented: maybeToEitherUnit" -- | Convert a 'Either () a' to…
fuuman
  • 469
  • 2
  • 7
  • 19
0
votes
1 answer

Error while compiling print Either value

I'm trying to compile simple code snippet. main = (putStrLn . show) (Right 3.423) Compile results in the following error: No instance for (Show a0) arising from a use of `show' The type variable `a0' is ambiguous Possible fix: add a type signature…
Alexander
  • 779
  • 8
  • 17
0
votes
2 answers

Project a sequence of 'Left's from a sequence of Eithers?

(Caveat - I'm a scala noob) Given a sequence of Eithers, viz theResults : Seq[Either[Error, String]] I am trying to extract all the Errors by using a map on the left(s) theResults match { case r if r.exists(_.isLeft) => { val errors =…
StuartLC
  • 104,537
  • 17
  • 209
  • 285
0
votes
1 answer

understanding data type in haskell

I am a haskell new bee. I can't just wrap my head around what is going on here data NestedList a=Elem a | List [NestedList a] deriving Show append::NestedList a->NestedList a->Either String (NestedList a) append (Elem x) (Elem y) = Right $ List…
user1792899
0
votes
1 answer

haskell Either String (NestedList a)- why doesn't it work

I am trying to append function that works on Nested Lists like regular lists. I want to use Either String (Nested a) so that it returns error or the appended list. But it keeps failing. I am not doing NestedList[NestedList a] anywhere. Why does it…
user1792899
0
votes
2 answers

for comprehensions with if guard throws error

I get one error when I use for comprehensions with if guard in this way. code: for { foo <- Left[String,String]("teststring").right bar <- Right[String,String]("teststring").right if (foo==bar) } yield (bar) error: error: type mismatch; found …
angelokh
  • 9,426
  • 9
  • 69
  • 139
-1
votes
1 answer

Why isn't Vavr Either is recognizing the parameter to map() function?

I am dirtying my hands with the fantastic library of vavr (0.9.2). Here's a code snippet, that aims to collect an Either: Either,String>, List> payloadPreparationResult = new…
Nirmalya
  • 717
  • 9
  • 19
-1
votes
1 answer

please suggest best way to write an anonymous function here

Please suggest best way to write an inline function at the place where func_1 is being called. Also it should do something what func_1 is trying to do (I am aware that a function cannot return two things in scala) I am reading lines from a…
-1
votes
1 answer

"Either Fmap" which Continues until a Right Result has been Reached

If Either fmap is (a -> b) -> p a a -> p a b which stops mapping once a Left is returned. What's name or type signature for a function which doesn't stop until it gets a Right result. I suspect a bifunctor, but I really need it spelled out - don't…
user3264325
  • 237
  • 1
  • 2
  • 9
-4
votes
1 answer

Couldn't match type Synonym with Either

I'm a beginner learning Haskell. But not so sure how Either works in pattern matching. Here is my code: type Rank = Either Pip Court type Pip = Int type Deck = [Card] data Card = Joker | Card Suit Rank data Court = Ace | Jack | Queen | King deriving…
1 2 3
22
23