Realizing the answer may be “Don’t get yourself in...
# arrow
i
Realizing the answer may be “Don’t get yourself into such a situation.” I’m wondering if there’s a way to convert an
Either<A, Either<A, B>>
into an
Either<A, B>
(Sorry for the basic question)
s
Copy code
val x: Either<Nothing, Either<Nothing, Int>> = 1.right().right()
val y: Either<Nothing, Int> = x.flatten()
works in
0.11.0
i
flatten()
! Outstanding, thanks Satyam!
r
Hi Ian, Satyam ! Ian, alternatively you may have a
map
that should had been a
flatMap
at the point you are nesting. Beside
flatten
which is the same as
flatMap(identity())
you can always use an
either
computation expressions to compose and extract the values in them:
Copy code
either {
   val nested = x.bind()
   val y = nested.bind()
   y // Int
}
👍 3