diff --git a/dev/iter/Iter/IO/index.html b/dev/iter/Iter/IO/index.html index 24ad335..9e6d6b2 100644 --- a/dev/iter/Iter/IO/index.html +++ b/dev/iter/Iter/IO/index.html @@ -1,5 +1,5 @@ -IO (iter.Iter.IO)

Module Iter.IO

val lines_of : ?mode:int -> ?flags:Stdlib.open_flag list -> string -> string t

lines_of filename reads all lines of the given file. It raises the same exception as would opening the file and read from it, except from End_of_file (which is caught). The file is always properly closed. Every time the iterator is iterated on, the file is opened again, so different iterations might return different results

  • parameter mode

    default 0o644

  • parameter flags

    default: [Open_rdonly]

val chunks_of : +IO (iter.Iter.IO)

Module Iter.IO

Basic IO

Very basic interface to manipulate files as iterator of chunks/lines. The iterators take care of opening and closing files properly; every time one iterates over an iterator, the file is opened/closed again.

Example: copy a file "a" into file "b", removing blank lines:

Iterator.(IO.lines_of "a" |> filter (fun l-> l<> "") |> IO.write_lines "b");;

By chunks of 4096 bytes:

Iterator.IO.(chunks_of ~size:4096 "a" |> write_to "b");;

Read the lines of a file into a list:

Iterator.IO.lines "a" |> Iterator.to_list
  • since 0.5.1
val lines_of : ?mode:int -> ?flags:Stdlib.open_flag list -> string -> string t

lines_of filename reads all lines of the given file. It raises the same exception as would opening the file and read from it, except from End_of_file (which is caught). The file is always properly closed. Every time the iterator is iterated on, the file is opened again, so different iterations might return different results

  • parameter mode

    default 0o644

  • parameter flags

    default: [Open_rdonly]

val chunks_of : ?mode:int -> ?flags:Stdlib.open_flag list -> ?size:int -> diff --git a/dev/iter/Iter/index.html b/dev/iter/Iter/index.html index 8f9ef9b..54eb5f6 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

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 : +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 -> @@ -53,4 +53,4 @@ ( Stdlib.Buffer.t -> 'a -> unit ) -> Stdlib.Buffer.t -> 'a t -> - unit

Print into a buffer

val to_string : ?sep:string -> ( 'a -> string ) -> 'a t -> string

Print into a string

Basic IO

Very basic interface to manipulate files as iterator of chunks/lines. The iterators take care of opening and closing files properly; every time one iterates over an iterator, the file is opened/closed again.

Example: copy a file "a" into file "b", removing blank lines:

Iterator.(IO.lines_of "a" |> filter (fun l-> l<> "") |> IO.write_lines "b");;

By chunks of 4096 bytes:

Iterator.IO.(chunks_of ~size:4096 "a" |> write_to "b");;

Read the lines of a file into a list:

Iterator.IO.lines "a" |> Iterator.to_list
  • since 0.5.1
module IO : sig ... end
\ No newline at end of file + unit

Print into a buffer

val to_string : ?sep:string -> ( 'a -> string ) -> 'a t -> string

Print into a string

module IO : sig ... end

Basic IO

\ No newline at end of file diff --git a/dev/iter/IterBigarray/index.html b/dev/iter/IterBigarray/index.html index 2adee77..9aef472 100644 --- a/dev/iter/IterBigarray/index.html +++ b/dev/iter/IterBigarray/index.html @@ -1,2 +1,2 @@ -IterBigarray (iter.IterBigarray)

Module IterBigarray

Interface and Helpers for bigarrays

  • since 0.5.4
val of_bigarray : ( 'a, _, _ ) Stdlib.Bigarray.Array1.t -> 'a Iter.t

Iterate on the elements of a 1-D array

val mmap : string -> char Iter.t

Map the file into memory, and read the characters.

\ No newline at end of file +IterBigarray (iter.IterBigarray)

Module IterBigarray

Interface and Helpers for bigarrays

  • since 0.5.4
val of_bigarray : ( 'a, _, _ ) Stdlib.Bigarray.Array1.t -> 'a Iter.t

Iterate on the elements of a 1-D array

val mmap : string -> char Iter.t

Map the file into memory, and read the characters.

\ No newline at end of file diff --git a/dev/iter/index.html b/dev/iter/index.html index 54949f1..afcd0d7 100644 --- a/dev/iter/index.html +++ b/dev/iter/index.html @@ -1,2 +1,2 @@ -index (iter.index)

iter index

Library iter

This library exposes the following toplevel modules:

Library iter.bigarray

This library exposes the following toplevel modules:

\ No newline at end of file +index (iter.index)

iter index

Library iter

This library exposes the following toplevel modules:

Library iter.bigarray

This library exposes the following toplevel modules:

\ No newline at end of file