🎉 Black Friday Sale! Save 30% when you subscribe today.
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.
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.