11 Monads

This chapter covers

  • Discussing type constructors
  • Introducing functors
  • Defining monads

In the previous chapter, we introduced a simple algebraic structure: the monoid. This was our first instance of a completely abstract, purely algebraic interface, and it led us to think about interfaces in a new way. A useful interface may be defined only by a collection of operations related by laws.

In this chapter, we’ll continue this mode of thinking and apply it to the problem of factoring out code duplication across some of the libraries we wrote in parts 1 and 2. We’ll discover two new abstract interfaces—Functor and Monad—and get more general experience with spotting these sorts of abstract structures in our code.1

11.1 Functors: Generalizing ...

Get Functional Programming in Scala, Second Edition 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.