瀏覽代碼

some Lwd_seq combinators

pre-release
Frédéric Bour 5 月之前
父節點
當前提交
1067a65207
共有 2 個文件被更改,包括 21 次插入7 次删除
  1. +15
    -7
      lib/lwd/lwd_seq.ml
  2. +6
    -0
      lib/lwd/lwd_seq.mli

+ 15
- 7
lib/lwd/lwd_seq.ml 查看文件

@ -482,17 +482,21 @@ let fold_monoid map (zero, reduce) seq =
let monoid = (empty, concat)
let of_list ls =
Lwd_utils.map_reduce element monoid ls
let bind_list ls f =
Lwd_utils.map_reduce f monoid ls
let rec of_sub_array arr i j =
let of_list ls = bind_list ls element
let rec of_sub_array f arr i j =
if j < i then empty
else if j = i then element arr.(i)
else if j = i then f arr.(i)
else
let k = i + (j - i) / 2 in
concat (of_sub_array arr i k) (of_sub_array arr (k + 1) j)
concat (of_sub_array f arr i k) (of_sub_array f arr (k + 1) j)
let bind_array arr f = of_sub_array f arr 0 (Array.length arr - 1)
let of_array arr = of_sub_array arr 0 (Array.length arr - 1)
let of_array arr = bind_array arr element
let to_list x =
let rec fold x acc = match x with
@ -547,4 +551,8 @@ let filter_map f seq =
fold_monoid select monoid seq
let lift (seq : 'a Lwd.t seq Lwd.t) : 'a seq Lwd.t =
Lwd.join (fold_monoid (Lwd.map element) (Lwd_utils.lift_monoid monoid) seq)
Lwd.join (fold_monoid (Lwd.map element) lwd_monoid seq)
let bind (seq : 'a seq Lwd.t) (f : 'a -> 'b seq) : 'b seq Lwd.t =
fold_monoid f monoid seq

+ 6
- 0
lib/lwd/lwd_seq.mli 查看文件

@ -39,6 +39,10 @@ val concat : 'a seq -> 'a seq -> 'a seq
val monoid : 'a t Lwd_utils.monoid
val lwd_monoid : 'a t Lwd.t Lwd_utils.monoid
(*val bind : 'a seq -> ('a -> 'b seq) -> 'b seq*)
val bind_list : 'a list -> ('a -> 'b seq) -> 'b seq
val bind_array : 'a array -> ('a -> 'b seq) -> 'b seq
val of_list : 'a list -> 'a seq
val of_array : 'a array -> 'a seq
val to_list : 'a seq -> 'a list
@ -112,6 +116,8 @@ val filter_map :
val lift : 'a Lwd.t seq Lwd.t -> 'a seq Lwd.t
val bind : 'a seq Lwd.t -> ('a -> 'b seq) -> 'b seq Lwd.t
(* Low-level interface *)
module Reducer : sig


Loading…
取消
儲存