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

NAME

6       Stdlib.Seq - no description
7

Module

9       Module   Stdlib.Seq
10

Documentation

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 flat_map : ('a -> 'b t) -> 'a t -> 'b t
102
103       Map  each  element  to  a subsequence, then return each element of this
104       sub-sequence in turn.  This transformation is  lazy,  it  only  applies
105       when the result is traversed.
106
107
108
109       val fold_left : ('a -> 'b -> 'a) -> 'a -> 'b t -> 'a
110
111       Traverse  the  sequence from left to right, combining each element with
112       the accumulator using the given function.  The traversal happens  imme‐
113       diately and will not terminate on infinite sequences.
114
115       Also see List.fold_left
116
117
118
119
120       val iter : ('a -> unit) -> 'a t -> unit
121
122       Iterate on the sequence, calling the (imperative) function on every el‐
123       ement.  The traversal happens immediately and will not terminate on in‐
124       finite sequences.
125
126
127
128       val unfold : ('b -> ('a * 'b) option) -> 'b -> 'a t
129
130       Build a sequence from a step function and an initial value.  unfold f u
131       returns empty if f u returns None , or fun () -> Cons (x, unfold  f  y)
132       if f u returns Some (x, y) .
133
134       For  example,  unfold  (function  [] -> None | h::t -> Some (h,t)) l is
135       equivalent to List.to_seq l .
136
137
138       Since 4.11
139
140
141
142
143
144OCamldoc                          2021-07-22                     Stdlib.Seq(3)
Impressum