February 2018
Intermediate to advanced
552 pages
13h 46m
English
Like Option, Scala source code has another Monad—Either. It works similarly to Option. It is defined in the scala.util package.
Like Option, Either[T] represents two kinds of data:
Unlike Option, which cannot represent why data is missing, Either represents success cases as Right, and failure cases as Left.
Unlike Try, which can represent why data is missing in terms of exception only, Either can define a failure scenario, either as a plain text or any useful object. It is a kind of sum type:

Here is an example:
import scala.util.{Either, Right, Left}
We can define a method signature using Either, as shown ...
Read now
Unlock full access