package links

  1. Overview
  2. Docs

This is the lazy evaluated sequence module for OCaml 4.06 compatability. The signatures and comments are based on the standard OCaml library.

type 'a t = unit -> 'a node
and 'a node =
  1. | Nil
  2. | Cons of 'a * 'a t
val empty : 'a t

The empty sequence, containing no elements.

val return : 'a -> 'a t

The singleton sequence containing only the given element.

val 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.

val 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.

val 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.

val 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

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

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

OCaml

Innovation. Community. Security.