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 @@ -
IterSimple 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.
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 tval from_iter : ( ( 'a -> unit ) -> unit ) -> 'a tBuild an iterator from a iter function
val from_labelled_iter : ( f:( 'a -> unit ) -> unit ) -> 'a tBuild an iterator from a labelled iter function
val from_fun : ( unit -> 'a option ) -> 'a tCall the function repeatedly until it returns None. This iterator is transient, use persistent if needed!
val empty : 'a tEmpty iterator. It contains no element.
val singleton : 'a -> 'a tSingleton iterator, with exactly one element.
val doubleton : 'a -> 'a -> 'a tIterator with exactly two elements
val init : ( int -> 'a ) -> 'a tinit f is the infinite iterator f 0; f 1; f 2; ….
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 repeat : 'a -> 'a tInfinite 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 titerate f x is the infinite iterator x, f(x), f(f(x)), ...
val forever : ( unit -> 'b ) -> 'b tIterator 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.
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 tunfoldr f b will apply f to b. If it yields Some (x,b') then x is returned and unfoldr recurses with b'.
val iter : ( 'a -> unit ) -> 'a t -> unitConsume the iterator, passing all its arguments to the function. Basically iter f seq is just seq f.
val iteri : ( int -> 'a -> unit ) -> 'a t -> unitIterate on elements and their index in the iterator
val for_each : 'a t -> ( 'a -> unit ) -> unitConsume 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 ) -> unitIterate 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 -> 'aFold over elements of the iterator, consuming it
val foldi : ( 'a -> int -> 'b -> 'a ) -> 'a -> 'b t -> 'aFold over elements of the iterator and their index, consuming it
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.
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 tCreation
val from_iter : ( ( 'a -> unit ) -> unit ) -> 'a tBuild an iterator from a iter function
val from_labelled_iter : ( f:( 'a -> unit ) -> unit ) -> 'a tBuild an iterator from a labelled iter function
val from_fun : ( unit -> 'a option ) -> 'a tCall the function repeatedly until it returns None. This iterator is transient, use persistent if needed!
val empty : 'a tEmpty iterator. It contains no element.
val singleton : 'a -> 'a tSingleton iterator, with exactly one element.
val doubleton : 'a -> 'a -> 'a tIterator with exactly two elements
val init : ( int -> 'a ) -> 'a tinit f is the infinite iterator f 0; f 1; f 2; ….
val repeat : 'a -> 'a tInfinite 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 titerate f x is the infinite iterator x, f(x), f(f(x)), ...
val forever : ( unit -> 'b ) -> 'b tIterator 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.
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 tunfoldr f b will apply f to b. If it yields Some (x,b') then x is returned and unfoldr recurses with b'.
Consumption
val iter : ( 'a -> unit ) -> 'a t -> unitConsume the iterator, passing all its arguments to the function. Basically iter f seq is just seq f.
val iteri : ( int -> 'a -> unit ) -> 'a t -> unitIterate on elements and their index in the iterator
val for_each : 'a t -> ( 'a -> unit ) -> unitConsume 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 ) -> unitIterate 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 -> 'aFold over elements of the iterator, consuming it
val foldi : ( 'a -> int -> 'b -> 'a ) -> 'a -> 'b t -> 'aFold over elements of the iterator and their index, consuming it
val fold_filter_map :
( 'acc -> 'a -> 'acc * 'b option ) ->
'acc ->
'a t ->