mirror of
https://github.com/c-cube/iter.git
synced 2026-01-28 12:04:50 -05:00
added scan combinator
This commit is contained in:
parent
b2c3de33a5
commit
b308a8ae87
2 changed files with 11 additions and 0 deletions
|
|
@ -226,6 +226,14 @@ let unfoldr f b =
|
||||||
in
|
in
|
||||||
from_iter (fun k -> unfold k b)
|
from_iter (fun k -> unfold k b)
|
||||||
|
|
||||||
|
(** Sequence of intermediate results *)
|
||||||
|
let scan f acc seq =
|
||||||
|
from_iter
|
||||||
|
(fun k ->
|
||||||
|
k acc;
|
||||||
|
let acc = ref acc in
|
||||||
|
seq (fun elt -> let acc' = f !acc elt in k acc'; acc := acc'))
|
||||||
|
|
||||||
(** Max element of the sequence, using the given comparison
|
(** Max element of the sequence, using the given comparison
|
||||||
function. A default element has to be provided. *)
|
function. A default element has to be provided. *)
|
||||||
let max ?(lt=fun x y -> x < y) seq m =
|
let max ?(lt=fun x y -> x < y) seq m =
|
||||||
|
|
|
||||||
|
|
@ -119,6 +119,9 @@ val unfoldr : ('b -> ('a * 'b) option) -> 'b -> 'a t
|
||||||
yields [Some (x,b')] then [x] is returned
|
yields [Some (x,b')] then [x] is returned
|
||||||
and unfoldr recurses with [b']. *)
|
and unfoldr recurses with [b']. *)
|
||||||
|
|
||||||
|
val scan : ('b -> 'a -> 'b) -> 'b -> 'a t -> 'b t
|
||||||
|
(** Sequence of intermediate results *)
|
||||||
|
|
||||||
val max : ?lt:('a -> 'a -> bool) -> 'a t -> 'a -> 'a
|
val max : ?lt:('a -> 'a -> bool) -> 'a t -> 'a -> 'a
|
||||||
(** Max element of the sequence, using the given comparison
|
(** Max element of the sequence, using the given comparison
|
||||||
function. A default element has to be provided. *)
|
function. A default element has to be provided. *)
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue