Lists
is support for nondeterministic computations. Maybe
computations can return either Nothing
or a Just
value, while List
computations can return zero, one or multiple values based on their length. Let's see how this is defined in the Monad
instance of List
:map
and concat
?return
method simply takes a value x
and puts it into a List
structure [x]
. The (>>=)
method for lists extracts all the values x
from the list m
and applies the function f
to each of them, combining all the results in one final list. As with the Maybe
monad, the bind operator, allows us to chain operations together with lists as well. With lists, these chaining operations will combine all output possibilities in a single result list.mitosis
function is applied to each element of the list, providing a resulting list to be passed to the subsequent functions.