All Posts

Functional Design Patterns in Scala: 3. Monads

Learning (and subsequently trying to explain) monads has become something of a rite of passage in functional programming. Burrito analogies aside, the most helpful description I have come across is given by Noel Welsh and Dave Gurnell in Scala with Cats:

“A monad is a mechanism for sequencing computations.”

Functional Design Patterns in Scala: 1. Monoids

Monoids are used to describe an aggregation pattern: whenever we need to combine values of a particular type, a monoid instance helps abstract the mechanics of the aggregation from the program’s business logic. In this post, we will use the LCD Digits kata that we tackled previously as a motivating example for applying this pattern. The goal here is to transform a sequence of input digits into a string resembling their representation on an LCD display.