Monad Transformers Just Why
summary
Claim: monads do not compose generically, but specific compositions are practical. Example: a messy Future[Option[A]] becomes OptionT[Future[Option[A]], A] (or OptionT[Future, A]) and using cats or scalaz removes nested flatMaps and cleans up code. Worked for several two-layer cases, but stacking more than two layers gets clunky and requires constant lifting. Alternatives that scale better include the free monad approach and libraries like F / M; don’t expose transformers at API boundaries.
AI-written summary · about
chapters (12)
- 0:00Introduction and speaker background
- 4:03Functors and monads basics
- 7:15Monads in Scala and for comprehensions
- 10:24Problem with nested monads
- 13:38Why monads don't compose freely
- 16:52Introducing monad transformers
- 20:05OptionT and how it works
- 22:11Limitations of monad transformers
- 24:57Practical example with ResultT
- 27:47Stacking more than two monads
- 31:03Tips for using monad transformers
- 33:11Takeaways and alternatives
