mirror of
https://github.com/c-cube/ocaml-containers.git
synced 2025-12-07 03:35:30 -05:00
monadic operator in CCList: map_m_par
This commit is contained in:
parent
e7660747d9
commit
f3cdb0943e
2 changed files with 14 additions and 0 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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} *)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue