O'Reilly logo

Functional PHP by Gilles Crettenand

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

List monad

The List or Collection monad represents the category of all functions taking a collection as a parameter and returning zero, one, or several values. The function is applied to all possible values in the input list and the results are concatenated to product a new collection.

An important thing to understand is that a list monad does not really represent a simple list of values, but rather a list of all different possible values for the monad. This idea is often described a non-determinism. As we saw with the CollectionApplicative function, this can lead to interesting results when you apply a collection of functions with a collection of values. We will try to expand on this topic in the examples to clarify this.

Motivation

The List monad ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required