Similar to the map()
method, this method invokes the
supplied partial function only if the supplied Either
is a
Right
.
Similar to the map()
method, this method invokes the
supplied partial function only if the supplied Either
is a
Right
. Unlike map()
, however, flatMap()
does
not automatically rewrap the result in a Right
; instead, it
expects the supplied partial function to return an Either
.
This method is roughly analogous to the Scala Option
class's
flatMap()
function.
the mapped Right
type
Partial function taking a value of type R
(i.e., what's stored in the Right
side) and maps
it to an Either[L, R2]
.
Map an Either
value only if it's a Right
.
Map an Either
value only if it's a Right
. If it's a
Left
, just return the Left
unmodified.
This method is roughly analogous to the Scala Option
class's
map()
function.
the mapped Right
type
Partial function taking a value of type R
(i.e., what's stored in the Right
side) and maps
it to a value of type R2
.
Convert an Either
to a Try
.
Convert an Either
to a Try
. If the Either
is a Right
, then
the value is extracted from the Right
and wrapped in a Success
.
If the Either
is a Left
, then the value is extracted from the
left, stored in an Exception
, and wrapped in a Failure
.
To convert the exception to another exception, you can use .orElse
:
either.toTry.orElse { e => Failure(new MyException(e)) }
the Either
, converted to a Try
Enriched
Either
class, providingmap
andflatMap
methods that map over andEither
object if its value isRight
(and permit easier use ofEither
objects infor
comprehensions).