diff --git a/dev/iter/Iter/index.html b/dev/iter/Iter/index.html index 44ed3f2..b4913b5 100644 --- a/dev/iter/Iter/index.html +++ b/dev/iter/Iter/index.html @@ -1,5 +1,5 @@ -Iter (iter.Iter)

Module Iter

Simple and Efficient Iterators.

The iterators are designed to allow easy transfer (mappings) between data structures, without defining n^2 conversions between the n types. The implementation relies on the assumption that an iterator can be iterated on as many times as needed; this choice allows for high performance of many combinators. However, for transient iterators, the persistent function is provided, storing elements of a transient iterator in memory; the iterator can then be used several times (See further).

Note that some combinators also return iterators (e.g. group). The transformation is computed on the fly every time one iterates over the resulting iterator. If a transformation performs heavy computation, persistent can also be used as intermediate storage.

Most functions are lazy, i.e. they do not actually use their arguments until their result is iterated on. For instance, if one calls map on an iterator, one gets a new iterator, but nothing else happens until this new iterator is used (by folding or iterating on it).

If an iterator is built from an iteration function that is repeatable (i.e. calling it several times always iterates on the same set of elements, for instance List.iter or Map.iter), then the resulting t object is also repeatable. For one-time iter functions such as iteration on a file descriptor or a Seq, the persistent function can be used to iterate and store elements in a memory structure; the result is an iterator that iterates on the elements of this memory structure, cheaply and repeatably.

type +'a t = ( 'a -> unit ) -> unit

An iterator of values of type 'a. If you give it a function 'a -> unit it will be applied to every element of the iterator successively.

type +'a iter = 'a t
type 'a equal = 'a -> 'a -> bool
type 'a hash = 'a -> int

Creation

val from_iter : ( ( 'a -> unit ) -> unit ) -> 'a t

Build an iterator from a iter function

val from_labelled_iter : ( f:( 'a -> unit ) -> unit ) -> 'a t

Build an iterator from a labelled iter function

  • since 1.2
val from_fun : ( unit -> 'a option ) -> 'a t

Call the function repeatedly until it returns None. This iterator is transient, use persistent if needed!

val empty : 'a t

Empty iterator. It contains no element.

val singleton : 'a -> 'a t

Singleton iterator, with exactly one element.

val doubleton : 'a -> 'a -> 'a t

Iterator with exactly two elements

val init : ( int -> 'a ) -> 'a t

init f is the infinite iterator f 0; f 1; f 2; ….

  • since 0.9
val cons : 'a -> 'a t -> 'a t

cons x l yields x, then yields from l. Same as append (singleton x) l.

Caution: it is advised not to build long iterators out of cons, because it's inefficient. Each additional cons x i adds one layer of function call per item traversed in i.

val snoc : 'a t -> 'a -> 'a t

Same as cons but yields the element after iterating on l.

val return : 'a -> 'a t

Synonym to singleton

val pure : 'a -> 'a t

Synonym to singleton

val repeat : 'a -> 'a t

Infinite iterator of the same element. You may want to look at take and the likes if you iterate on it.

val iterate : ( 'a -> 'a ) -> 'a -> 'a t

iterate f x is the infinite iterator x, f(x), f(f(x)), ...

val forever : ( unit -> 'b ) -> 'b t

Iterator that calls the given function to produce elements. The iterator may be transient (depending on the function), and definitely is infinite. You may want to use take and persistent.

val cycle : 'a t -> 'a t

Cycle forever through the given iterator. Assume the given iterator can be traversed any amount of times (not transient). This yields an infinite iterator, you should use something like take not to loop forever.

val unfoldr : ( 'b -> ('a * 'b) option ) -> 'b -> 'a t

unfoldr f b will apply f to b. If it yields Some (x,b') then x is returned and unfoldr recurses with b'.

val scan : ( 'b -> 'a -> 'b ) -> 'b -> 'a t -> 'b t

Iterator of intermediate results

Consumption

val iter : ( 'a -> unit ) -> 'a t -> unit

Consume the iterator, passing all its arguments to the function. Basically iter f seq is just seq f.

val iteri : ( int -> 'a -> unit ) -> 'a t -> unit

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.

  • since 1.4
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.

  • since 1.4
val fold : ( 'a -> 'b -> 'a ) -> 'a -> 'b t -> 'a

Fold over elements of the iterator, consuming it

val foldi : ( 'a -> int -> 'b -> 'a ) -> 'a -> 'b t -> 'a

Fold over elements of the iterator and their index, consuming it

val fold_map : ( 'acc -> 'a -> 'acc * 'b ) -> 'acc -> 'a t -> 'b t

fold_map f acc l is like map, but it carries some state as in fold. The state is not returned, it is just used to thread some information to the map function.

  • since 0.9
val fold_filter_map : +Iter (iter.Iter)

Module Iter

Simple and Efficient Iterators.

The iterators are designed to allow easy transfer (mappings) between data structures, without defining n^2 conversions between the n types. The implementation relies on the assumption that an iterator can be iterated on as many times as needed; this choice allows for high performance of many combinators. However, for transient iterators, the persistent function is provided, storing elements of a transient iterator in memory; the iterator can then be used several times (See further).

Note that some combinators also return iterators (e.g. group). The transformation is computed on the fly every time one iterates over the resulting iterator. If a transformation performs heavy computation, persistent can also be used as intermediate storage.

Most functions are lazy, i.e. they do not actually use their arguments until their result is iterated on. For instance, if one calls map on an iterator, one gets a new iterator, but nothing else happens until this new iterator is used (by folding or iterating on it).

If an iterator is built from an iteration function that is repeatable (i.e. calling it several times always iterates on the same set of elements, for instance List.iter or Map.iter), then the resulting t object is also repeatable. For one-time iter functions such as iteration on a file descriptor or a Seq, the persistent function can be used to iterate and store elements in a memory structure; the result is an iterator that iterates on the elements of this memory structure, cheaply and repeatably.

type +'a t = ( 'a -> unit ) -> unit

An iterator of values of type 'a. If you give it a function 'a -> unit it will be applied to every element of the iterator successively.

type +'a iter = 'a t
type 'a equal = 'a -> 'a -> bool
type 'a hash = 'a -> int

Creation

val from_iter : ( ( 'a -> unit ) -> unit ) -> 'a t

Build an iterator from a iter function

val from_labelled_iter : ( f:( 'a -> unit ) -> unit ) -> 'a t

Build an iterator from a labelled iter function

  • since 1.2
val from_fun : ( unit -> 'a option ) -> 'a t

Call the function repeatedly until it returns None. This iterator is transient, use persistent if needed!

val empty : 'a t

Empty iterator. It contains no element.

val singleton : 'a -> 'a t

Singleton iterator, with exactly one element.

val doubleton : 'a -> 'a -> 'a t

Iterator with exactly two elements

val init : ( int -> 'a ) -> 'a t

init f is the infinite iterator f 0; f 1; f 2; ….

  • since 0.9
val cons : 'a -> 'a t -> 'a t

cons x l yields x, then yields from l. Same as append (singleton x) l

val snoc : 'a t -> 'a -> 'a t

Same as cons but yields the element after iterating on l

val return : 'a -> 'a t

Synonym to singleton

val pure : 'a -> 'a t

Synonym to singleton

val repeat : 'a -> 'a t

Infinite iterator of the same element. You may want to look at take and the likes if you iterate on it.

val iterate : ( 'a -> 'a ) -> 'a -> 'a t

iterate f x is the infinite iterator x, f(x), f(f(x)), ...

val forever : ( unit -> 'b ) -> 'b t

Iterator that calls the given function to produce elements. The iterator may be transient (depending on the function), and definitely is infinite. You may want to use take and persistent.

val cycle : 'a t -> 'a t

Cycle forever through the given iterator. Assume the given iterator can be traversed any amount of times (not transient). This yields an infinite iterator, you should use something like take not to loop forever.

val unfoldr : ( 'b -> ('a * 'b) option ) -> 'b -> 'a t

unfoldr f b will apply f to b. If it yields Some (x,b') then x is returned and unfoldr recurses with b'.

val scan : ( 'b -> 'a -> 'b ) -> 'b -> 'a t -> 'b t

Iterator of intermediate results

Consumption

val iter : ( 'a -> unit ) -> 'a t -> unit

Consume the iterator, passing all its arguments to the function. Basically iter f seq is just seq f.

val iteri : ( int -> 'a -> unit ) -> 'a t -> unit

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.

  • since 1.4
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.

  • since 1.4
val fold : ( 'a -> 'b -> 'a ) -> 'a -> 'b t -> 'a

Fold over elements of the iterator, consuming it

val foldi : ( 'a -> int -> 'b -> 'a ) -> 'a -> 'b t -> 'a

Fold over elements of the iterator and their index, consuming it

val fold_map : ( 'acc -> 'a -> 'acc * 'b ) -> 'acc -> 'a t -> 'b t

fold_map f acc l is like map, but it carries some state as in fold. The state is not returned, it is just used to thread some information to the map function.

  • since 0.9
val fold_filter_map : ( 'acc -> 'a -> 'acc * 'b option ) -> 'acc -> 'a t ->