1Stream(3) OCaml library Stream(3)
2
3
4
6 Stream - Streams and parsers.
7
9 Module Stream
10
12 Module Stream
13 : sig end
14
15
16 Streams and parsers.
17
18
19
20
21
22
23 type 'a t
24
25
26 The type of streams holding values of type 'a .
27
28
29
30
31 exception Failure
32
33
34 Raised by parsers when none of the first components of the stream pat‐
35 terns is accepted.
36
37
38
39
40 exception Error of string
41
42
43 Raised by parsers when the first component of a stream pattern is
44 accepted, but one of the following components is rejected.
45
46
47
48
49
50 === Stream builders Warning: these functions create streams with fast
51 access; it is illegal to mix them with streams built with [< >]; would
52 raise Failure when accessing such mixed streams. ===
53
54
55 val from : (int -> 'a option) -> 'a t
56
57
58 Stream.from f returns a stream built from the function f . To create a
59 new stream element, the function f is called with the current stream
60 count. The user function f must return either Some <value> for a value
61 or None to specify the end of the stream.
62
63
64
65
66 val of_list : 'a list -> 'a t
67
68 Return the stream holding the elements of the list in the same order.
69
70
71
72
73 val of_string : string -> char t
74
75 Return the stream of the characters of the string parameter.
76
77
78
79
80 val of_channel : Pervasives.in_channel -> char t
81
82 Return the stream of the characters read from the input channel.
83
84
85
86
87
88 === Stream iterator ===
89
90
91 val iter : ('a -> unit) -> 'a t -> unit
92
93
94 Stream.iter f s scans the whole stream s, applying function f in turn
95 to each stream element encountered.
96
97
98
99
100
101 === Predefined parsers ===
102
103
104 val next : 'a t -> 'a
105
106 Return the first element of the stream and remove it from the stream.
107 Raise Stream.Failure if the stream is empty.
108
109
110
111
112 val empty : 'a t -> unit
113
114 Return () if the stream is empty, else raise Stream.Failure .
115
116
117
118
119
120 === Useful functions ===
121
122
123 val peek : 'a t -> 'a option
124
125 Return Some of "the first element" of the stream, or None if the stream
126 is empty.
127
128
129
130
131 val junk : 'a t -> unit
132
133 Remove the first element of the stream, possibly unfreezing it before.
134
135
136
137
138 val count : 'a t -> int
139
140 Return the current count of the stream elements, i.e. the number of the
141 stream elements discarded.
142
143
144
145
146 val npeek : int -> 'a t -> 'a list
147
148
149 npeek n returns the list of the n first elements of the stream, or all
150 its remaining elements if less than n elements are available.
151
152
153
154
155
156
157OCamldoc 2010-01-29 Stream(3)