liveBook · Manning

Chapter 11: Second abstract nonsense interlude: Monads

What you will learn in chapter 11 of Fabulous Adventures in Data Structures and Algorithms

This chapter introduction frames monads as common patterns for adding capabilities to existing types and structuring programs as chained workflows.

After this chapter you will be able to

What it builds on

Section by section

Introduction

This chapter introduction frames monads as common patterns for adding capabilities to existing types and structuring programs as chained workflows.

Key terms: monads, design patterns, chained operations, workflows, divide by 2, nullability, laziness, asynchrony, Map, Bind

11.1 What’s the value for OO programmers?

This section presents monads to OO programmers as composable generic wrapper types that add capabilities while preserving an existing program workflow.

Key terms: monad, generic type, M<T>, workflow, capability, Nullable<T>, Func<T>, Lazy<T>, Task<T>, IObservable<T>

11.2 How hard can it be to divide by 2?

This section lifts a simple divide-by-two function into nullable, lazy, task, and sequence contexts to show that each monad determines how values are unwrapped, transformed, and rewrapped.

Key terms: nullable, null, underlying value, lazy, lambda, Task<double>, await, asynchronously, sequence, loop

11.3 Generalizing to arbitrary functions with Map and Bind

This section generalizes monadic workflows by introducing Map, Bind, and Join, and states the minimal Unit-and-Bind definition of a monad.

Key terms: Map, Lazy<T>, Lazy<R>, monad, Lazy<Lazy<double>>, Nullable<Nullable<R>>, Task<Task<R>>, IEnumerable<IEnumerable<R>>, Bind, M<T>

11.4 The sequence monad is an additive monad

This section shows that sequences form an additive monad, relating familiar sequence operations to Map, Bind, Unit, filtering, concatenation, and the empty sequence.

Key terms: Map, Bind, Select, SelectMany, flatMap, Where, filter, predicate, Unit, MZero

11.5 Summary

This summary recaps monads as generic wrappers with Unit and Bind, their derived operations, and the additive behavior of the sequence monad.

Where this is used later

Concepts explained in this chapter

← Chapter 10: Unification and anti-unification Chapter 12: A better abstraction for randomness →

These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.