Why it matters
Monads are Scala's compositional workhorse. Understanding shapes idiomatic code.
Advertisement
The architecture
Monad: type with unit (pure) and flatMap (bind).
for-comprehension: syntactic sugar for flatMap chains.
Advertisement
How it works end to end
Option.flatMap: chain nullable computations without null checks.
Either.flatMap: chain error-carrying computations.
Future.flatMap: chain async without callbacks.
for-comprehension: 'for { x <- a; y <- b } yield x + y' desugars to flatMap chain.