1Seq(3)                           OCaml library                          Seq(3)
2
3
4

NAME

6       Seq -  Functional Iterators
7

Module

9       Module   Seq
10

Documentation

12       Module Seq
13        : sig end
14
15
16
17       Functional Iterators
18
19
20
21
22
23
24
25
26       ===  The type 'a t is a delayed list, i.e. a list where some evaluation
27       is needed to access the next element. This makes it possible  to  build
28       infinite  sequences,  to  build  sequences  as we traverse them, and to
29       transform them in a lazy fashion rather than upfront. ===
30
31
32       type 'a t = unit -> 'a node
33
34
35       The type of delayed lists containing elements of type 'a .   Note  that
36       the  concrete  list node 'a node is delayed under a closure, not a lazy
37       block, which means it might be recomputed every time we access it.
38
39
40       type 'a node =
41        | Nil
42        | Cons of 'a * 'a t
43         (* A fully-evaluated list node, either empty or containing an element
44       and a delayed tail.
45        *)
46
47
48
49
50
51       val empty : 'a t
52
53       The empty sequence, containing no elements.
54
55
56
57       val return : 'a -> 'a t
58
59       The singleton sequence containing only the given element.
60
61
62
63       val map : ('a -> 'b) -> 'a t -> 'b t
64
65
66       map f seq returns a new sequence whose elements are the elements of seq
67       , transformed by f .  This transformation is lazy, it only applies when
68       the result is traversed.
69
70       If seq = [1;2;3] , then map f seq = [f 1; f 2; f 3] .
71
72
73
74       val filter : ('a -> bool) -> 'a t -> 'a t
75
76       Remove  from  the  sequence  the elements that do not satisfy the given
77       predicate.  This transformation is  lazy,  it  only  applies  when  the
78       result is traversed.
79
80
81
82       val filter_map : ('a -> 'b option) -> 'a t -> 'b t
83
84       Apply  the  function to every element; if f x = None then x is dropped;
85       if f x = Some y then y is returned.  This transformation  is  lazy,  it
86       only applies when the result is traversed.
87
88
89
90       val flat_map : ('a -> 'b t) -> 'a t -> 'b t
91
92       Map  each  element  to  a subsequence, then return each element of this
93       sub-sequence in turn.  This transformation is  lazy,  it  only  applies
94       when the result is traversed.
95
96
97
98       val fold_left : ('a -> 'b -> 'a) -> 'a -> 'b t -> 'a
99
100       Traverse  the  sequence from left to right, combining each element with
101       the accumulator using the given function.  The traversal happens  imme‐
102       diately and will not terminate on infinite sequences.
103
104       Also see List.fold_left
105
106
107
108
109       val iter : ('a -> unit) -> 'a t -> unit
110
111       Iterate  on  the  sequence,  calling the (imperative) function on every
112       element.  The traversal happens immediately and will not  terminate  on
113       infinite sequences.
114
115
116
117
118
119OCamldoc                          2019-02-02                            Seq(3)
Impressum