package seq

  1. Overview
  2. Docs
Compatibility package for OCaml's standard iterator type starting from 4.07

Install

Dune Dependency

Authors

Maintainers

Sources

v0.3.1.tar.gz
md5=de05d9dedd492fa4e3c0c87bc2792475
sha512=06ce767d3ec1532f8a2421d033f4d9dc5c08c9a27574754d456c31a71ecb9a3c33857591b7d24f85492dce679cd0da8c8985c9fb1a5b5a7f8588d90056b663b8

doc/seq/Seq_redef/index.html

Module Seq_redefSource

Functional Iterators

The type 'a t is a delayed list, i.e. a list where some evaluation is needed to access the next element. This makes it possible to build infinite sequences, to build sequences as we traverse them, and to transform them in a lazy fashion rather than upfront.

Sourcetype 'a t = unit -> 'a node

The type of delayed lists containing elements of type 'a. Note that the concrete list node 'a node is delayed under a closure, not a lazy block, which means it might be recomputed every time we access it.

Sourceand +'a node =
  1. | Nil
  2. | Cons of 'a * 'a t
    (*

    A fully-evaluated list node, either empty or containing an element and a delayed tail.

    *)
Sourceval empty : 'a t

The empty sequence, containing no elements.

Sourceval return : 'a -> 'a t

The singleton sequence containing only the given element.

Sourceval map : ('a -> 'b) -> 'a t -> 'b t

map f seq returns a new sequence whose elements are the elements of seq, transformed by f. This transformation is lazy, it only applies when the result is traversed.

If seq = [1;2;3], then map f seq = [f 1; f 2; f 3].

Sourceval filter : ('a -> bool) -> 'a t -> 'a t

Remove from the sequence the elements that do not satisfy the given predicate. This transformation is lazy, it only applies when the result is traversed.

Sourceval filter_map : ('a -> 'b option) -> 'a t -> 'b t

Apply the function to every element; if f x = None then x is dropped; if f x = Some y then y is returned. This transformation is lazy, it only applies when the result is traversed.

Sourceval flat_map : ('a -> 'b t) -> 'a t -> 'b t

Map each element to a subsequence, then return each element of this sub-sequence in turn. This transformation is lazy, it only applies when the result is traversed.

Sourceval fold_left : ('a -> 'b -> 'a) -> 'a -> 'b t -> 'a

Traverse the sequence from left to right, combining each element with the accumulator using the given function. The traversal happens immediately and will not terminate on infinite sequences.

Also see List.fold_left

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

Iterate on the sequence, calling the (imperative) function on every element. The traversal happens immediately and will not terminate on infinite sequences.

OCaml

Innovation. Community. Security.