diff --git a/core/CCList.ml b/core/CCList.ml index 72d5ff87..2fca2327 100644 --- a/core/CCList.ml +++ b/core/CCList.ml @@ -526,6 +526,15 @@ module Traverse(M : MONAD) = struct aux f (x' :: acc) tail in aux f [] l + let rec map_m_par f l = match l with + | [] -> M.return [] + | x::tl -> + let x' = f x in + let tl' = map_m_par f tl in + x' >>= fun x' -> + tl' >>= fun tl' -> + M.return (x'::tl') + let sequence_m l = map_m (fun x->x) l let rec fold_m f acc l = match l with diff --git a/core/CCList.mli b/core/CCList.mli index 281a6616..6a72b547 100644 --- a/core/CCList.mli +++ b/core/CCList.mli @@ -236,6 +236,11 @@ module Traverse(M : MONAD) : sig val fold_m : ('b -> 'a -> 'b M.t) -> 'b -> 'a t -> 'b M.t val map_m : ('a -> 'b M.t) -> 'a t -> 'b t M.t + + val map_m_par : ('a -> 'b M.t) -> 'a t -> 'b t M.t + (** Same as {!map_m} but [map_m_par f (x::l)] evaluates [f x] and + [f l] "in parallel" before combining their result (for instance + in Lwt). *) end (** {2 Conversions} *)