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