Module CCList.Traverse
Monadic 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.
Parameters
Signature
val sequence_m : 'a M.t t -> 'a t M.tTraverse the list of monadic values using
M.(>>=), re-combining elements with(::). See the documentation of theTraversefunctor itself.
val fold_m : ('b -> 'a -> 'b M.t) -> 'b -> 'a t -> 'b M.tFold a function with a monadic effect through a list.
val map_m_par : ('a -> 'b M.t) -> 'a t -> 'b t M.tmap_m_par f (x :: l)is likemap_mbutf xandf lare evaluated "in parallel" before combining their result (for instance in Lwt).Basically, when encoutering
x :: tl, this computesf xandmap_m_par f tl, and only then isM.(>>=)used to combine the two results into a new list.