Exploring monads by applying test-driven development

Monads are used in functional programming to build simple components. They are used to chain a series of operations in a safe way. Each component encapsulates a value and makes sure that the next component that is called could handle its output as input. For example, if component A generates nil (null) as output and the next component in the chain cannot handle nil as input, the computation of the chain will be stopped automatically.

In Haskell, a pure functional programming language, monads are used prominently. Still, they can be useful in other functional programming languages as well. We will take a brief and very high-level look at monads here and skip a lot of complex theory and background ...

Get Introduction to JVM Languages now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.