Flat‑Map

Section • 5 episodes • 2 hr 26 min

The flatMap operation completes the functional trio, and gives us the power to sequence computations. Where map allowed us to transform a single computation, and zip allowed us to transform many independent computations at once, flatMap instead allows us to run one computation after another so that each subsequent computation can depend on the result of the previous one.

Related content

When exploring ways to cook up complex form of randomness, such as randomly sized arrays of random values, we were naturally led to the concept of flatMap. It was exactly what we needed to allow new random values to depend on previous random values.

Predictable Randomness: Part 2
37 min