Is it possible to handle Either
in similar way to Option
? In Option
, I have a getOrElse
function, in Either
I want to return Left
or process Right
. I'm looking for the fastest way of doing this without any boilerplate like:
val myEither:Either[String, Object] = Right(new Object())
myEither match {
case Left(leftValue) => value
case Right(righValue) =>
"Success"
}
In Scala 2.12,
so you can do
myEither.map(_ => "Success").merge
if you find it more readable than fold
.