CCList.Traverse
This allows the traversal of a 'a t list
where _ t
is also a monad.
For example, a 'a option list
will be traversed by extracting a value from each option, returning Some [x1;…;x_n]
; but if one of the option is None
then the whole result is None
.
Another example is with result
: ('a, 'err) result list
can be transformed into ('a list, 'err) result
by returning the first error, or Ok [x1; …; xn]
if all the elements were successful.
This describes the behavior of sequence_m
; map_m
is a combination of map
and sequence_m
; map_m_par
is like map_m
but useful for some pseudo monads like Lwt.
Fold a function with a monadic effect through a list.
map_m_par f (x :: l)
is like map_m
but f x
and f l
are evaluated "in parallel" before combining their result (for instance in Lwt).
Basically, when encoutering x :: tl
, this computes f x
and map_m_par f tl
, and only then is M.(>>=)
used to combine the two results into a new list.