diff --git a/dev/iter/Iter/.dune-keep b/dev/iter/Iter/.dummy similarity index 100% rename from dev/iter/Iter/.dune-keep rename to dev/iter/Iter/.dummy diff --git a/dev/iter/Iter/index.html b/dev/iter/Iter/index.html index 80a15b1..658ed8c 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 Stream, 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

NOTE Type ('a, 'b) t2 = ('a -> 'b -> unit) -> unit has been removed and subsumed by ('a * 'b) 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 : +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

NOTE Type ('a, 'b) t2 = ('a -> 'b -> unit) -> unit has been removed and subsumed by ('a * 'b) t

  • since 1.0
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 -> @@ -37,13 +37,13 @@ ( 'a -> 'b -> 'c ) -> ( 'a -> 'b -> 'd ) -> ('a * 'b) t -> - ('c * 'd) t

map2_2 f g seq2 maps each x, y of seq2 into f x y, g x y

Data structures converters

val to_list : 'a t -> 'a list

Convert the iterator into a list. Preserves order of elements. This function is tail-recursive, but consumes 2*n memory. If order doesn't matter to you, consider to_rev_list.

val to_rev_list : 'a t -> 'a list

Get the list of the reversed iterator (more efficient than to_list)

val of_list : 'a list -> 'a t
val on_list : ( 'a t -> 'b t ) -> 'a list -> 'b list

on_list f l is equivalent to to_list @@ f @@ of_list l.

  • since 0.5.2
val pair_with_idx : 'a t -> (int * 'a) t

Similar to zip_i but returns a normal iterator of tuples

  • since 0.11
val to_opt : 'a t -> 'a option

Alias to head

  • since 0.5.1
val to_array : 'a t -> 'a array

Convert to an array. Currently not very efficient because an intermediate list is used.

val of_array : 'a array -> 'a t
val of_array_i : 'a array -> (int * 'a) t

Elements of the array, with their index

val array_slice : 'a array -> int -> int -> 'a t

array_slice a i j Iterator of elements whose indexes range from i to j

val of_opt : 'a option -> 'a t

Iterate on 0 or 1 values.

  • since 0.5.1
val of_stream : 'a Stdlib.Stream.t -> 'a t

Iterator of elements of a stream (usable only once)

val to_stream : 'a t -> 'a Stdlib.Stream.t

Convert to a stream. linear in memory and time (a copy is made in memory)

val to_stack : 'a Stdlib.Stack.t -> 'a t -> unit

Push elements of the iterator on the stack

val of_stack : 'a Stdlib.Stack.t -> 'a t

Iterator of elements of the stack (same order as Stack.iter)

val to_queue : 'a Stdlib.Queue.t -> 'a t -> unit

Push elements of the iterator into the queue

val of_queue : 'a Stdlib.Queue.t -> 'a t

Iterator of elements contained in the queue, FIFO order

val hashtbl_add : ( 'a, 'b ) Stdlib.Hashtbl.t -> ('a * 'b) t -> unit

Add elements of the iterator to the hashtable, with Hashtbl.add

val hashtbl_replace : ( 'a, 'b ) Stdlib.Hashtbl.t -> ('a * 'b) t -> unit

Add elements of the iterator to the hashtable, with Hashtbl.replace (erases conflicting bindings)

val to_hashtbl : ('a * 'b) t -> ( 'a, 'b ) Stdlib.Hashtbl.t

Build a hashtable from an iterator of key/value pairs

val of_hashtbl : ( 'a, 'b ) Stdlib.Hashtbl.t -> ('a * 'b) t

Iterator of key/value pairs from the hashtable

val hashtbl_keys : ( 'a, 'b ) Stdlib.Hashtbl.t -> 'a t
val hashtbl_values : ( 'a, 'b ) Stdlib.Hashtbl.t -> 'b t
val of_str : string -> char t
val to_str : char t -> string
val concat_str : string t -> string

Concatenate strings together, eagerly. Also see intersperse to add a separator.

  • since 0.5
exception OneShotSequence

Raised when the user tries to iterate several times on a transient iterator

val of_in_channel : Stdlib.in_channel -> char t

Iterates on characters of the input (can block when one iterates over the iterator). If you need to iterate several times on this iterator, use persistent.

  • raises OneShotIterator

    when used more than once.

val to_buffer : char t -> Stdlib.Buffer.t -> unit

Copy content of the iterator into the buffer

val int_range : start:int -> stop:int -> int t

Iterator on integers in start...stop by steps 1. Also see (--) for an infix version.

val int_range_dec : start:int -> stop:int -> int t

Iterator on decreasing integers in stop...start by steps -1. See (--^) for an infix version

val int_range_by : step:int -> int -> int -> int t

int_range_by ~step i j is the range starting at i, including j, where the difference between successive elements is step. use a negative step for a decreasing iterator.

  • raises Invalid_argument

    if step=0

val bools : bool t

Iterates on true and false

  • since 0.7
val of_set : + ('c * 'd) t

map2_2 f g seq2 maps each x, y of seq2 into f x y, g x y

Data structures converters

val to_list : 'a t -> 'a list

Convert the iterator into a list. Preserves order of elements. This function is tail-recursive, but consumes 2*n memory. If order doesn't matter to you, consider to_rev_list.

val to_rev_list : 'a t -> 'a list

Get the list of the reversed iterator (more efficient than to_list)

val of_list : 'a list -> 'a t
val on_list : ( 'a t -> 'b t ) -> 'a list -> 'b list

on_list f l is equivalent to to_list @@ f @@ of_list l.

  • since 0.5.2
val pair_with_idx : 'a t -> (int * 'a) t

Similar to zip_i but returns a normal iterator of tuples

  • since 0.11
val to_opt : 'a t -> 'a option

Alias to head

  • since 0.5.1
val to_array : 'a t -> 'a array

Convert to an array. Currently not very efficient because an intermediate list is used.

val of_array : 'a array -> 'a t
val of_array_i : 'a array -> (int * 'a) t

Elements of the array, with their index

val array_slice : 'a array -> int -> int -> 'a t

array_slice a i j Iterator of elements whose indexes range from i to j

val of_opt : 'a option -> 'a t

Iterate on 0 or 1 values.

  • since 0.5.1
val of_seq : 'a Stdlib.Seq.t -> 'a t

Iterator of elements of a Seq.t.

  • since NEXT_RELEASE
val to_seq_persistent : 'a t -> 'a Stdlib.Seq.t

Convert to a Seq. Linear in memory and time (a copy is made in memory). This does not work on infinite iterators.

  • since NEXT_RELEASE
val to_stack : 'a Stdlib.Stack.t -> 'a t -> unit

Push elements of the iterator on the stack

val of_stack : 'a Stdlib.Stack.t -> 'a t

Iterator of elements of the stack (same order as Stack.iter)

val to_queue : 'a Stdlib.Queue.t -> 'a t -> unit

Push elements of the iterator into the queue

val of_queue : 'a Stdlib.Queue.t -> 'a t

Iterator of elements contained in the queue, FIFO order

val hashtbl_add : ( 'a, 'b ) Stdlib.Hashtbl.t -> ('a * 'b) t -> unit

Add elements of the iterator to the hashtable, with Hashtbl.add

val hashtbl_replace : ( 'a, 'b ) Stdlib.Hashtbl.t -> ('a * 'b) t -> unit

Add elements of the iterator to the hashtable, with Hashtbl.replace (erases conflicting bindings)

val to_hashtbl : ('a * 'b) t -> ( 'a, 'b ) Stdlib.Hashtbl.t

Build a hashtable from an iterator of key/value pairs

val of_hashtbl : ( 'a, 'b ) Stdlib.Hashtbl.t -> ('a * 'b) t

Iterator of key/value pairs from the hashtable

val hashtbl_keys : ( 'a, 'b ) Stdlib.Hashtbl.t -> 'a t
val hashtbl_values : ( 'a, 'b ) Stdlib.Hashtbl.t -> 'b t
val of_str : string -> char t
val to_str : char t -> string
val concat_str : string t -> string

Concatenate strings together, eagerly. Also see intersperse to add a separator.

  • since 0.5
exception OneShotSequence

Raised when the user tries to iterate several times on a transient iterator

val of_in_channel : Stdlib.in_channel -> char t

Iterates on characters of the input (can block when one iterates over the iterator). If you need to iterate several times on this iterator, use persistent.

  • raises OneShotIterator

    when used more than once.

val to_buffer : char t -> Stdlib.Buffer.t -> unit

Copy content of the iterator into the buffer

val int_range : start:int -> stop:int -> int t

Iterator on integers in start...stop by steps 1. Also see (--) for an infix version.

val int_range_dec : start:int -> stop:int -> int t

Iterator on decreasing integers in stop...start by steps -1. See (--^) for an infix version

val int_range_by : step:int -> int -> int -> int t

int_range_by ~step i j is the range starting at i, including j, where the difference between successive elements is step. use a negative step for a decreasing iterator.

  • raises Invalid_argument

    if step=0

val bools : bool t

Iterates on true and false

  • since 0.7
val of_set : (module Stdlib.Set.S with type elt = 'a and type t = 'b) -> 'b -> 'a t

Convert the given set to an iterator. The set module must be provided.

val to_set : (module Stdlib.Set.S with type elt = 'a and type t = 'b) -> 'a t -> - 'b

Convert the iterator to a set, given the proper set module

type 'a gen = unit -> 'a option
type 'a klist = unit -> [ `Nil | `Cons of 'a * 'a klist ]
val of_gen : 'a gen -> 'a t

Traverse eagerly the generator and build an iterator from it

val to_gen : 'a t -> 'a gen

Make the iterator persistent (O(n)) and then iterate on it. Eager.

val of_klist : 'a klist -> 'a t

Iterate on the lazy list

val to_klist : 'a t -> 'a klist

Make the iterator persistent and then iterate on it. Eager.

Sets

module Set : sig ... end

Maps

module Map : sig ... end

Random iterators

val random_int : int -> int t

Infinite iterator of random integers between 0 and the given higher bound (see Random.int)

val random_bool : bool t

Infinite iterator of random bool values

val random_float : float -> float t
val random_array : 'a array -> 'a t

Iterator of choices of an element in the array

val random_list : 'a list -> 'a t

Infinite iterator of random elements of the list. Basically the same as random_array.

val shuffle : 'a t -> 'a t

shuffle seq returns a perfect shuffle of seq. Uses O(length seq) memory and time. Eager.

  • since 0.7
val shuffle_buffer : int -> 'a t -> 'a t

shuffle_buffer n seq returns an iterator of element of seq in random order. The shuffling is *not* uniform. Uses O(n) memory.

The first n elements of the iterator are consumed immediately. The rest is consumed lazily.

  • since 0.7

Sampling

val sample : int -> 'a t -> 'a array

sample n seq returns k samples of seq, with uniform probability. It will consume the iterator and use O(n) memory.

It returns an array of size min (length seq) n.

  • since 0.7

Infix functions

module Infix : sig ... end
include module type of Infix
val (--) : int -> int -> int t

a -- b is the range of integers from a to b, both included, in increasing order. It will therefore be empty if a > b.

val (--^) : int -> int -> int t

a --^ b is the range of integers from b to a, both included, in decreasing order (starts from a). It will therefore be empty if a < b.

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

Monadic bind (infix version of flat_map

  • since 0.5
val (>|=) : 'a t -> ( 'a -> 'b ) -> 'b t

Infix version of map

  • since 0.5
val (<*>) : ( 'a -> 'b ) t -> 'a t -> 'b t

Applicative operator (product+application)

  • since 0.5
val (<+>) : 'a t -> 'a t -> 'a t

Concatenation of iterators

  • since 0.5

Pretty printing

val pp_seq : + 'b

Convert the iterator to a set, given the proper set module

type 'a gen = unit -> 'a option
val of_gen : 'a gen -> 'a t

Traverse eagerly the generator and build an iterator from it

val of_gen_once : 'a gen -> 'a t

One shot iterator using this generator. It must not be traversed twice.

  • since NEXT_RELEASE
val to_gen : 'a t -> 'a gen

Make the iterator persistent (O(n)) and then iterate on it. Eager.

Sets

module Set : sig ... end

Maps

module Map : sig ... end

Random iterators

val random_int : int -> int t

Infinite iterator of random integers between 0 and the given higher bound (see Random.int)

val random_bool : bool t

Infinite iterator of random bool values

val random_float : float -> float t
val random_array : 'a array -> 'a t

Iterator of choices of an element in the array

val random_list : 'a list -> 'a t

Infinite iterator of random elements of the list. Basically the same as random_array.

val shuffle : 'a t -> 'a t

shuffle seq returns a perfect shuffle of seq. Uses O(length seq) memory and time. Eager.

  • since 0.7
val shuffle_buffer : int -> 'a t -> 'a t

shuffle_buffer n seq returns an iterator of element of seq in random order. The shuffling is *not* uniform. Uses O(n) memory.

The first n elements of the iterator are consumed immediately. The rest is consumed lazily.

  • since 0.7

Sampling

val sample : int -> 'a t -> 'a array

sample n seq returns k samples of seq, with uniform probability. It will consume the iterator and use O(n) memory.

It returns an array of size min (length seq) n.

  • since 0.7

Infix functions

module Infix : sig ... end
include module type of Infix
val (--) : int -> int -> int t

a -- b is the range of integers from a to b, both included, in increasing order. It will therefore be empty if a > b.

val (--^) : int -> int -> int t

a --^ b is the range of integers from b to a, both included, in decreasing order (starts from a). It will therefore be empty if a < b.

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

Monadic bind (infix version of flat_map

  • since 0.5
val (>|=) : 'a t -> ( 'a -> 'b ) -> 'b t

Infix version of map

  • since 0.5
val (<*>) : ( 'a -> 'b ) t -> 'a t -> 'b t

Applicative operator (product+application)

  • since 0.5
val (<+>) : 'a t -> 'a t -> 'a t

Concatenation of iterators

  • since 0.5

Pretty printing

val pp_seq : ?sep:string -> ( Stdlib.Format.formatter -> 'a -> unit ) -> Stdlib.Format.formatter -> diff --git a/dev/iter/IterBigarray/.dune-keep b/dev/iter/IterBigarray/.dummy similarity index 100% rename from dev/iter/IterBigarray/.dune-keep rename to dev/iter/IterBigarray/.dummy diff --git a/dev/iter/IterBigarrayShims_/.dune-keep b/dev/iter/IterBigarrayShims_/.dummy similarity index 100% rename from dev/iter/IterBigarrayShims_/.dune-keep rename to dev/iter/IterBigarrayShims_/.dummy diff --git a/dev/iter/IterLabels/.dune-keep b/dev/iter/IterLabels/.dummy similarity index 100% rename from dev/iter/IterLabels/.dune-keep rename to dev/iter/IterLabels/.dummy diff --git a/dev/iter/IterLabels/index.html b/dev/iter/IterLabels/index.html index c263a93..6d92626 100644 --- a/dev/iter/IterLabels/index.html +++ b/dev/iter/IterLabels/index.html @@ -41,13 +41,13 @@ f:( 'a -> 'b -> 'c ) -> ( 'a -> 'b -> 'd ) -> ('a * 'b) t -> - ('c * 'd) t

map2_2 f g seq2 maps each x, y of seq2 into f x y, g x y

Data structures converters

val to_list : 'a t -> 'a list

Convert the iterator into a list. Preserves order of elements. This function is tail-recursive, but consumes 2*n memory. If order doesn't matter to you, consider to_rev_list.

val to_rev_list : 'a t -> 'a list

Get the list of the reversed iterator (more efficient than to_list)

val of_list : 'a list -> 'a t
val on_list : ( 'a t -> 'b t ) -> 'a list -> 'b list

on_list f l is equivalent to to_list @@ f @@ of_list l.

  • since 0.5.2
val pair_with_idx : 'a t -> (int * 'a) t

Similar to zip_i but returns a normal iterator of tuples

  • since 0.11
val to_opt : 'a t -> 'a option

Alias to head

  • since 0.5.1
val to_array : 'a t -> 'a array

Convert to an array. Currently not very efficient because an intermediate list is used.

val of_array : 'a array -> 'a t
val of_array_i : 'a array -> (int * 'a) t

Elements of the array, with their index

val array_slice : 'a array -> int -> int -> 'a t

array_slice a i j Iterator of elements whose indexes range from i to j

val of_opt : 'a option -> 'a t

Iterate on 0 or 1 values.

  • since 0.5.1
val of_stream : 'a Stdlib.Stream.t -> 'a t

Iterator of elements of a stream (usable only once)

val to_stream : 'a t -> 'a Stdlib.Stream.t

Convert to a stream. linear in memory and time (a copy is made in memory)

val to_stack : 'a Stdlib.Stack.t -> 'a t -> unit

Push elements of the iterator on the stack

val of_stack : 'a Stdlib.Stack.t -> 'a t

Iterator of elements of the stack (same order as Stack.iter)

val to_queue : 'a Stdlib.Queue.t -> 'a t -> unit

Push elements of the iterator into the queue

val of_queue : 'a Stdlib.Queue.t -> 'a t

Iterator of elements contained in the queue, FIFO order

val hashtbl_add : ( 'a, 'b ) Stdlib.Hashtbl.t -> ('a * 'b) t -> unit

Add elements of the iterator to the hashtable, with Hashtbl.add

val hashtbl_replace : ( 'a, 'b ) Stdlib.Hashtbl.t -> ('a * 'b) t -> unit

Add elements of the iterator to the hashtable, with Hashtbl.replace (erases conflicting bindings)

val to_hashtbl : ('a * 'b) t -> ( 'a, 'b ) Stdlib.Hashtbl.t

Build a hashtable from an iterator of key/value pairs

val of_hashtbl : ( 'a, 'b ) Stdlib.Hashtbl.t -> ('a * 'b) t

Iterator of key/value pairs from the hashtable

val hashtbl_keys : ( 'a, 'b ) Stdlib.Hashtbl.t -> 'a t
val hashtbl_values : ( 'a, 'b ) Stdlib.Hashtbl.t -> 'b t
val of_str : string -> char t
val to_str : char t -> string
val concat_str : string t -> string

Concatenate strings together, eagerly. Also see intersperse to add a separator.

  • since 0.5
exception OneShotSequence

Raised when the user tries to iterate several times on a transient iterator

val of_in_channel : Stdlib.in_channel -> char t

Iterates on characters of the input (can block when one iterates over the iterator). If you need to iterate several times on this iterator, use persistent.

  • raises OneShotIterator

    when used more than once.

val to_buffer : char t -> Stdlib.Buffer.t -> unit

Copy content of the iterator into the buffer

val int_range : start:int -> stop:int -> int t

Iterator on integers in start...stop by steps 1. Also see (--) for an infix version.

val int_range_dec : start:int -> stop:int -> int t

Iterator on decreasing integers in stop...start by steps -1. See (--^) for an infix version

val int_range_by : step:int -> start:int -> stop:int -> int t

int_range_by ~step ~start:i ~stop:j is the range starting at i, including j, where the difference between successive elements is step. use a negative step for a decreasing iterator.

  • since 0.9
  • raises Invalid_argument

    if step=0

val bools : bool t

Iterates on true and false

  • since 0.9
val of_set : + ('c * 'd) t

map2_2 f g seq2 maps each x, y of seq2 into f x y, g x y

Data structures converters

val to_list : 'a t -> 'a list

Convert the iterator into a list. Preserves order of elements. This function is tail-recursive, but consumes 2*n memory. If order doesn't matter to you, consider to_rev_list.

val to_rev_list : 'a t -> 'a list

Get the list of the reversed iterator (more efficient than to_list)

val of_list : 'a list -> 'a t
val on_list : ( 'a t -> 'b t ) -> 'a list -> 'b list

on_list f l is equivalent to to_list @@ f @@ of_list l.

  • since 0.5.2
val pair_with_idx : 'a t -> (int * 'a) t

Similar to zip_i but returns a normal iterator of tuples

  • since 0.11
val to_opt : 'a t -> 'a option

Alias to head

  • since 0.5.1
val to_array : 'a t -> 'a array

Convert to an array. Currently not very efficient because an intermediate list is used.

val of_array : 'a array -> 'a t
val of_array_i : 'a array -> (int * 'a) t

Elements of the array, with their index

val array_slice : 'a array -> int -> int -> 'a t

array_slice a i j Iterator of elements whose indexes range from i to j

val of_opt : 'a option -> 'a t

Iterate on 0 or 1 values.

  • since 0.5.1
val of_seq : 'a Stdlib.Seq.t -> 'a t

Iterator of elements of a Seq.t.

  • since NEXT_RELEASE
val to_seq_persistent : 'a t -> 'a Stdlib.Seq.t

Convert to a Seq. Linear in memory and time (a copy is made in memory). This does not work on infinite iterators.

  • since NEXT_RELEASE
val to_stack : 'a Stdlib.Stack.t -> 'a t -> unit

Push elements of the iterator on the stack

val of_stack : 'a Stdlib.Stack.t -> 'a t

Iterator of elements of the stack (same order as Stack.iter)

val to_queue : 'a Stdlib.Queue.t -> 'a t -> unit

Push elements of the iterator into the queue

val of_queue : 'a Stdlib.Queue.t -> 'a t

Iterator of elements contained in the queue, FIFO order

val hashtbl_add : ( 'a, 'b ) Stdlib.Hashtbl.t -> ('a * 'b) t -> unit

Add elements of the iterator to the hashtable, with Hashtbl.add

val hashtbl_replace : ( 'a, 'b ) Stdlib.Hashtbl.t -> ('a * 'b) t -> unit

Add elements of the iterator to the hashtable, with Hashtbl.replace (erases conflicting bindings)

val to_hashtbl : ('a * 'b) t -> ( 'a, 'b ) Stdlib.Hashtbl.t

Build a hashtable from an iterator of key/value pairs

val of_hashtbl : ( 'a, 'b ) Stdlib.Hashtbl.t -> ('a * 'b) t

Iterator of key/value pairs from the hashtable

val hashtbl_keys : ( 'a, 'b ) Stdlib.Hashtbl.t -> 'a t
val hashtbl_values : ( 'a, 'b ) Stdlib.Hashtbl.t -> 'b t
val of_str : string -> char t
val to_str : char t -> string
val concat_str : string t -> string

Concatenate strings together, eagerly. Also see intersperse to add a separator.

  • since 0.5
exception OneShotSequence

Raised when the user tries to iterate several times on a transient iterator

val of_in_channel : Stdlib.in_channel -> char t

Iterates on characters of the input (can block when one iterates over the iterator). If you need to iterate several times on this iterator, use persistent.

  • raises OneShotIterator

    when used more than once.

val to_buffer : char t -> Stdlib.Buffer.t -> unit

Copy content of the iterator into the buffer

val int_range : start:int -> stop:int -> int t

Iterator on integers in start...stop by steps 1. Also see (--) for an infix version.

val int_range_dec : start:int -> stop:int -> int t

Iterator on decreasing integers in stop...start by steps -1. See (--^) for an infix version

val int_range_by : step:int -> start:int -> stop:int -> int t

int_range_by ~step ~start:i ~stop:j is the range starting at i, including j, where the difference between successive elements is step. use a negative step for a decreasing iterator.

  • since 0.9
  • raises Invalid_argument

    if step=0

val bools : bool t

Iterates on true and false

  • since 0.9
val of_set : (module Stdlib.Set.S with type elt = 'a and type t = 'b) -> 'b -> 'a t

Convert the given set to an iterator. The set module must be provided.

val to_set : (module Stdlib.Set.S with type elt = 'a and type t = 'b) -> 'a t -> - 'b

Convert the iterator to a set, given the proper set module

type 'a gen = unit -> 'a option
type 'a klist = unit -> [ `Nil | `Cons of 'a * 'a klist ]
val of_gen : 'a gen -> 'a t

Traverse eagerly the generator and build an iterator from it

val to_gen : 'a t -> 'a gen

Make the iterator persistent (O(n)) and then iterate on it. Eager.

val of_klist : 'a klist -> 'a t

Iterate on the lazy list

val to_klist : 'a t -> 'a klist

Make the iterator persistent and then iterate on it. Eager.

Sets

module Set : sig ... end

Maps

module Map : sig ... end

Random iterators

val random_int : int -> int t

Infinite iterator of random integers between 0 and the given higher bound (see Random.int)

val random_bool : bool t

Infinite iterator of random bool values

val random_float : float -> float t
val random_array : 'a array -> 'a t

Iterator of choices of an element in the array

val random_list : 'a list -> 'a t

Infinite iterator of random elements of the list. Basically the same as random_array.

val shuffle : 'a t -> 'a t

shuffle seq returns a perfect shuffle of seq. Uses O(length seq) memory and time. Eager.

  • since 0.7
val shuffle_buffer : n:int -> 'a t -> 'a t

shuffle_buffer n seq returns an iterator of element of seq in random order. The shuffling is not uniform. Uses O(n) memory.

The first n elements of the iterator are consumed immediately. The rest is consumed lazily.

  • since 0.7

Sampling

val sample : n:int -> 'a t -> 'a array

sample n seq returns k samples of seq, with uniform probability. It will consume the iterator and use O(n) memory.

It returns an array of size min (length seq) n.

  • since 0.7

Infix functions

module Infix : sig ... end
include module type of Infix
val (--) : int -> int -> int t

a -- b is the range of integers from a to b, both included, in increasing order. It will therefore be empty if a > b.

val (--^) : int -> int -> int t

a --^ b is the range of integers from b to a, both included, in decreasing order (starts from a). It will therefore be empty if a < b.

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

Monadic bind (infix version of flat_map

  • since 0.5
val (>|=) : 'a t -> ( 'a -> 'b ) -> 'b t

Infix version of map

  • since 0.5
val (<*>) : ( 'a -> 'b ) t -> 'a t -> 'b t

Applicative operator (product+application)

  • since 0.5
val (<+>) : 'a t -> 'a t -> 'a t

Concatenation of iterators

  • since 0.5

Pretty printing

val pp_seq : + 'b

Convert the iterator to a set, given the proper set module

type 'a gen = unit -> 'a option
val of_gen : 'a gen -> 'a t

Traverse eagerly the generator and build an iterator from it

val of_gen_once : 'a gen -> 'a t

One shot iterator using this generator. It must not be traversed twice.

  • since NEXT_RELEASE
val to_gen : 'a t -> 'a gen

Make the iterator persistent (O(n)) and then iterate on it. Eager.

Sets

module Set : sig ... end

Maps

module Map : sig ... end

Random iterators

val random_int : int -> int t

Infinite iterator of random integers between 0 and the given higher bound (see Random.int)

val random_bool : bool t

Infinite iterator of random bool values

val random_float : float -> float t
val random_array : 'a array -> 'a t

Iterator of choices of an element in the array

val random_list : 'a list -> 'a t

Infinite iterator of random elements of the list. Basically the same as random_array.

val shuffle : 'a t -> 'a t

shuffle seq returns a perfect shuffle of seq. Uses O(length seq) memory and time. Eager.

  • since 0.7
val shuffle_buffer : n:int -> 'a t -> 'a t

shuffle_buffer n seq returns an iterator of element of seq in random order. The shuffling is not uniform. Uses O(n) memory.

The first n elements of the iterator are consumed immediately. The rest is consumed lazily.

  • since 0.7

Sampling

val sample : n:int -> 'a t -> 'a array

sample n seq returns k samples of seq, with uniform probability. It will consume the iterator and use O(n) memory.

It returns an array of size min (length seq) n.

  • since 0.7

Infix functions

module Infix : sig ... end
include module type of Infix
val (--) : int -> int -> int t

a -- b is the range of integers from a to b, both included, in increasing order. It will therefore be empty if a > b.

val (--^) : int -> int -> int t

a --^ b is the range of integers from b to a, both included, in decreasing order (starts from a). It will therefore be empty if a < b.

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

Monadic bind (infix version of flat_map

  • since 0.5
val (>|=) : 'a t -> ( 'a -> 'b ) -> 'b t

Infix version of map

  • since 0.5
val (<*>) : ( 'a -> 'b ) t -> 'a t -> 'b t

Applicative operator (product+application)

  • since 0.5
val (<+>) : 'a t -> 'a t -> 'a t

Concatenation of iterators

  • since 0.5

Pretty printing

val pp_seq : ?sep:string -> ( Stdlib.Format.formatter -> 'a -> unit ) -> Stdlib.Format.formatter -> diff --git a/dev/iter/Iter_shims_/.dune-keep b/dev/iter/Iter_shims_/.dummy similarity index 100% rename from dev/iter/Iter_shims_/.dune-keep rename to dev/iter/Iter_shims_/.dummy