The chain of flat-mapped computations is short-circuited on the first evaluated Left
due to Either
monad being success-biased on the Right
values. The reason for such bias is programers often interpreted left side to represent an error result of computation whilst the right hand side would mean the successful result of computation. So if left means error, there is not much point in continuing computing with error down the chain, hence the chain is broken.
Note, Either
monad used to biased only by convention. Conventional right-bias of Either
was formalised in Scala 2.12. Some argue Either
should be unbiased, for example,
If you use Either for error reporting, then it is true that you want
it to be biased to one side, but that is only one usecase of many, and
hardcoding a single special usecase into a general interface smells of
bad design. And for that usecase, you might just as well use Try,
which is basically a biased Either.
whilst others argue favouring one side, for example,
... with Scala 2.12. it became right-biased, which is IMHO a better
design choice, and fits perfectly with other similar sum types from
other libraries. For example, it's very easy now to go from Either to
/ (scalaz dicjuntion) now that there is no bias mismatch. They are
completely isomorphic.
Nevertheless, bias of Either
does not force semantics of just "happy/unhappy", for example, the requirement in Creating a method which returns one or two parameters may be addressed with Either
where left side is interpreted as a happy/successful value.
map
&flatMap
only work on the Right and shortcircuit when you have a Left. – Luis Miguel Mejía Suárez Sep 18 at 14:52