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