Module Base__Import0.Seq
Functional Iterators
type 'a t= unit -> 'a nodeThe type of delayed lists containing elements of type
'a. Note that the concrete list node'a nodeis delayed under a closure, not alazyblock, which means it might be recomputed every time we access it.
and +'a node=|Nil|Cons of 'a * 'a tA fully-evaluated list node, either empty or containing an element and a delayed tail.
val empty : 'a tThe empty sequence, containing no elements.
val return : 'a -> 'a tThe singleton sequence containing only the given element.
val map : ('a -> 'b) -> 'a t -> 'b tmap f seqreturns a new sequence whose elements are the elements ofseq, transformed byf. This transformation is lazy, it only applies when the result is traversed.If
seq = [1;2;3], thenmap f seq = [f 1; f 2; f 3].
val filter : ('a -> bool) -> 'a t -> 'a tRemove 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 tApply the function to every element; if
f x = Nonethenxis dropped; iff x = Some ythenyis returned. This transformation is lazy, it only applies when the result is traversed.
val flat_map : ('a -> 'b t) -> 'a t -> 'b tMap 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.
val fold_left : ('a -> 'b -> 'a) -> 'a -> 'b t -> 'aTraverse 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 -> unitIterate on the sequence, calling the (imperative) function on every element. The traversal happens immediately and will not terminate on infinite sequences.