Either, you will see, is kind of a in-between
Try to experiment to see the similarity and differences.
Option, you can create
Either in two ways:
Rightwhich would be similar to
Leftwhich, over time, became similar to
None, except you can store information. I am saying “over time” because up until Scala v2.12+,
Eitherwas not Right-bias.
Rightwere just two Types. But now,
Leftis accepting to carry error messages and
Rightto be the channel for successes.
You can test which Type is
isRight. You can also use
flatMap, etc… once again. You must be starting to know those functions pretty well by now. This is where the Right-bias come into play.
map will take a function that modify the type contained in
Right and will not do anything if the
Either contains a
If you would like to specifically act on
Right, you can use the
.right methods to project the
Either on one side of the other. For instance, to modify the content of the
Left when it is there, you can do
One major difference with
Try is that
Either will not catch the Exception. If an exception is thrown inside an
Either it will propagate. Inside a
Try it will be captured inside the