mirror of
https://github.com/c-cube/iter.git
synced 2025-12-05 19:00:31 -05:00
Added for_each and for_eachi
This commit is contained in:
parent
40891d29aa
commit
84061bcb69
4 changed files with 33 additions and 9 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
|
@ -7,3 +7,4 @@ man/
|
||||||
*.install
|
*.install
|
||||||
.merlin
|
.merlin
|
||||||
.gh-pages
|
.gh-pages
|
||||||
|
_opam
|
||||||
|
|
|
||||||
|
|
@ -82,6 +82,10 @@ let iteri f seq =
|
||||||
f !r x;
|
f !r x;
|
||||||
incr r)
|
incr r)
|
||||||
|
|
||||||
|
let for_each seq f = iter f seq
|
||||||
|
|
||||||
|
let for_eachi seq f = iteri f seq
|
||||||
|
|
||||||
let fold f init seq =
|
let fold f init seq =
|
||||||
let r = ref init in
|
let r = ref init in
|
||||||
seq (fun elt -> r := f !r elt);
|
seq (fun elt -> r := f !r elt);
|
||||||
|
|
|
||||||
13
src/Iter.mli
13
src/Iter.mli
|
|
@ -118,7 +118,17 @@ val iter : ('a -> unit) -> 'a t -> unit
|
||||||
Basically [iter f seq] is just [seq f]. *)
|
Basically [iter f seq] is just [seq f]. *)
|
||||||
|
|
||||||
val iteri : (int -> 'a -> unit) -> 'a t -> unit
|
val iteri : (int -> 'a -> unit) -> 'a t -> unit
|
||||||
(** Iterate on elements and their index in the iterator *)
|
(** Iterate on elements and their index in the iterator *)
|
||||||
|
|
||||||
|
val for_each : 'a t -> ('a -> unit) -> unit
|
||||||
|
(** Consume the iterator, passing all its arguments to the function.
|
||||||
|
[for_each seq f] is the same as [iter f seq], i.e., [iter] with
|
||||||
|
arguments reversed. *)
|
||||||
|
|
||||||
|
val for_eachi : 'a t -> (int -> 'a -> unit) -> unit
|
||||||
|
(** Iterate on elements and their index in the iterator.
|
||||||
|
[for_eachi seq f] is the same as [iteri f seq], i.e., [iteri] with
|
||||||
|
arguments reversed. *)
|
||||||
|
|
||||||
val fold : ('a -> 'b -> 'a) -> 'a -> 'b t -> 'a
|
val fold : ('a -> 'b -> 'a) -> 'a -> 'b t -> 'a
|
||||||
(** Fold over elements of the iterator, consuming it *)
|
(** Fold over elements of the iterator, consuming it *)
|
||||||
|
|
@ -849,4 +859,3 @@ module IO : sig
|
||||||
string -> Bytes.t t -> unit
|
string -> Bytes.t t -> unit
|
||||||
(** @since 0.5.4 *)
|
(** @since 0.5.4 *)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -88,6 +88,16 @@ val iter : f:('a -> unit) -> 'a t -> unit
|
||||||
val iteri : f:(int -> 'a -> unit) -> 'a t -> unit
|
val iteri : f:(int -> 'a -> unit) -> 'a t -> unit
|
||||||
(** Iterate on elements and their index in the iterator *)
|
(** Iterate on elements and their index in the iterator *)
|
||||||
|
|
||||||
|
val for_each : seq:'a t -> ('a -> unit) -> unit
|
||||||
|
(** Consume the iterator, passing all its arguments to the function.
|
||||||
|
[for_each seq f] is the same as [iter f seq], i.e., [iter] with
|
||||||
|
arguments reversed. *)
|
||||||
|
|
||||||
|
val for_eachi : seq:'a t -> (int -> 'a -> unit) -> unit
|
||||||
|
(** Iterate on elements and their index in the iterator.
|
||||||
|
[for_eachi seq f] is the same as [iteri f seq], i.e., [iteri] with
|
||||||
|
arguments reversed. *)
|
||||||
|
|
||||||
val fold : f:('a -> 'b -> 'a) -> init:'a -> 'b t -> 'a
|
val fold : f:('a -> 'b -> 'a) -> init:'a -> 'b t -> 'a
|
||||||
(** Fold over elements of the iterator, consuming it *)
|
(** Fold over elements of the iterator, consuming it *)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue