Scala Either map Right or return Left

Michał Jurczuk picture Michał Jurczuk · Dec 31, 2015 · Viewed 17.7k times · Source

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"
}

Answer