Monads are in danger of becoming a bit of a joke: for every person who raves about them, there’s another person asking what in the world they are, and a third person writing a confusing tutorial about them. With their technical-sounding name and forbidding reputation, monads can seem like a complex, abstract idea that’s only relevant to mathematicians and Haskell programmers.
Forget all that! In this pragmatic talk we roll up our sleeves and get stuck into refactoring some awkward Ruby code, using the good parts of monads to tackle the problems we encounter along the way. We see how the straightforward design pattern underlying monads can help us to make our code simpler, clearer and more reusable by uncovering its hidden structure, and we all leave with a shared understanding of what monads actually are and why people won’t shut up about them.
Given at eurucamp 2014 (http://2014.eurucamp.org/), BaRuCo 2014 (http://lanyrd.com/2014/baruco/) and GoGaRuCo 2014 (http://lanyrd.com/2014/gogaruco/). The accompanying code is at https://github.com/tomstuart/monads, and an article version is available at https://tomstu.art/refactoring-ruby-with-monads.