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