1Stdlib.Seq(3) OCaml library Stdlib.Seq(3)
2
3
4
6 Stdlib.Seq - no description
7
9 Module Stdlib.Seq
10
12 Module Seq
13 : (module Stdlib__Seq)
14
15
16
17
18
19
20
21 type 'a t = unit -> 'a node
22
23
24 The type of delayed lists containing elements of type 'a . Note that
25 the concrete list node 'a node is delayed under a closure, not a lazy
26 block, which means it might be recomputed every time we access it.
27
28
29 type 'a node =
30 | Nil
31 | Cons of 'a * 'a t
32
33
34 A fully-evaluated list node, either empty or containing an element and
35 a delayed tail.
36
37
38
39 val empty : 'a t
40
41 The empty sequence, containing no elements.
42
43
44
45 val return : 'a -> 'a t
46
47 The singleton sequence containing only the given element.
48
49
50
51 val cons : 'a -> 'a t -> 'a t
52
53
54 cons x xs is the sequence containing the element x followed by the se‐
55 quence xs
56
57
58
59 Since 4.11
60
61
62
63 val append : 'a t -> 'a t -> 'a t
64
65
66 append xs ys is the sequence xs followed by the sequence ys
67
68
69
70 Since 4.11
71
72
73
74 val map : ('a -> 'b) -> 'a t -> 'b t
75
76
77 map f seq returns a new sequence whose elements are the elements of seq
78 , transformed by f . This transformation is lazy, it only applies when
79 the result is traversed.
80
81 If seq = [1;2;3] , then map f seq = [f 1; f 2; f 3] .
82
83
84
85 val filter : ('a -> bool) -> 'a t -> 'a t
86
87 Remove from the sequence the elements that do not satisfy the given
88 predicate. This transformation is lazy, it only applies when the re‐
89 sult is traversed.
90
91
92
93 val filter_map : ('a -> 'b option) -> 'a t -> 'b t
94
95 Apply the function to every element; if f x = None then x is dropped;
96 if f x = Some y then y is returned. This transformation is lazy, it
97 only applies when the result is traversed.
98
99
100
101 val concat : 'a t t -> 'a t
102
103 concatenate a sequence of sequences.
104
105
106 Since 4.13
107
108
109
110 val flat_map : ('a -> 'b t) -> 'a t -> 'b t
111
112 Map each element to a subsequence, then return each element of this
113 sub-sequence in turn. This transformation is lazy, it only applies
114 when the result is traversed.
115
116
117
118 val concat_map : ('a -> 'b t) -> 'a t -> 'b t
119
120 Alias for Seq.flat_map .
121
122
123 Since 4.13
124
125
126
127 val fold_left : ('a -> 'b -> 'a) -> 'a -> 'b t -> 'a
128
129 Traverse the sequence from left to right, combining each element with
130 the accumulator using the given function. The traversal happens imme‐
131 diately and will not terminate on infinite sequences.
132
133 Also see List.fold_left
134
135
136
137
138 val iter : ('a -> unit) -> 'a t -> unit
139
140 Iterate on the sequence, calling the (imperative) function on every el‐
141 ement. The traversal happens immediately and will not terminate on in‐
142 finite sequences.
143
144
145
146 val unfold : ('b -> ('a * 'b) option) -> 'b -> 'a t
147
148 Build a sequence from a step function and an initial value. unfold f u
149 returns empty if f u returns None , or fun () -> Cons (x, unfold f y)
150 if f u returns Some (x, y) .
151
152 For example, unfold (function [] -> None | h::t -> Some (h,t)) l is
153 equivalent to List.to_seq l .
154
155
156 Since 4.11
157
158
159
160
161
162OCamldoc 2022-02-04 Stdlib.Seq(3)