mirror of
https://github.com/c-cube/ocaml-containers.git
synced 2025-12-06 03:05:28 -05:00
Enum.reduce
This commit is contained in:
parent
ebbf4a9138
commit
dfbce71324
2 changed files with 11 additions and 2 deletions
5
enum.ml
5
enum.ml
|
|
@ -144,6 +144,11 @@ let fold2 f acc e1 e2 =
|
|||
with EOG -> ());
|
||||
!acc
|
||||
|
||||
let reduce f enum =
|
||||
let gen = enum () in
|
||||
let acc = try gen () with EOG -> raise (Invalid_argument "reduce") in
|
||||
Gen.fold f acc gen
|
||||
|
||||
(** Successive values of the accumulator *)
|
||||
let scan f acc e =
|
||||
fun () ->
|
||||
|
|
|
|||
8
enum.mli
8
enum.mli
|
|
@ -95,7 +95,11 @@ val fold : ('b -> 'a -> 'b) -> 'b -> 'a t -> 'b
|
|||
(** Fold on the generator *)
|
||||
|
||||
val fold2 : ('c -> 'a -> 'b -> 'c) -> 'c -> 'a t -> 'b t -> 'c
|
||||
(** Fold on the two enums in parallel *)
|
||||
(** Fold on the two enums in parallel. Stops once one of the enums
|
||||
is exhausted. *)
|
||||
|
||||
val reduce : ('a -> 'a -> 'a) -> 'a t -> 'a
|
||||
(** Fold on non-empty sequences (otherwise raise Invalid_argument) *)
|
||||
|
||||
val scan : ('b -> 'a -> 'b) -> 'b -> 'a t -> 'b t
|
||||
(** Successive values of the accumulator *)
|
||||
|
|
@ -104,7 +108,7 @@ val iter : ('a -> unit) -> 'a t -> unit
|
|||
(** Iterate on the enum *)
|
||||
|
||||
val iter2 : ('a -> 'b -> unit) -> 'a t -> 'b t -> unit
|
||||
(** Iterate on the two sequences *)
|
||||
(** Iterate on the two sequences. Stops once one of them is exhausted.*)
|
||||
|
||||
val length : _ t -> int
|
||||
(** Length of an enum (linear time) *)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue