Legend:
Library
Module
Module type
Parameter
Class
Class type
Streams and stream parsers
Streams are a read-and-forget data structure, comparable to enumerations. In Batteries Included, streams are deprecated in favor of enumerations, defined in module BatEnum.
Note This module is provided essentially for backwards-compatibility. If you feel like using Stream.t, please take a look at BatEnum or LazyList.
Stream.from f returns a stream built from the function f. To create a new stream element, the function f is called with the current stream count. The user function f must return either Some <value> for a value or None to specify the end of the stream.
Return the stream of the characters read from the input channel.
Other Stream builders
Warning: these functions create streams with fast access; it is illegal to mix them with streams built with [< >]; would raise Failure when accessing such mixed streams.
Stream.of_fun f returns a stream built from the function f. To create a new stream element, the function f is called with the current stream count. The user function f must return either Some <value> for a value or None to specify the end of the stream.
Stream.iter f s scans the whole stream s, applying function f in turn to each stream element encountered.
val foldl : ('a->'b->'a * bool option)->'a->'bt->'a
foldl f init stream is a lazy fold_left. f accu elt should return (new_accu, state) where new_accu is normal accumulation result, and state is a flag representing whether the computation should continue and whether the last operation is valid: None means continue, Some b means stop where b = true means the last addition is still valid and b
= false means the last addition is invalid and should be revert.
foldr f init stream is a lazy fold_right. Unlike the normal fold_right, the accumulation parameter of f elt accu is lazy, hence it can decide not to force the evaluation of accu if the current element elt can determin the result by itself.
fold is foldl without initialization value, where the first element of stream is taken as init. It raises End_of_stream exception when the input stream is empty.
Convert a stream to an enumeration. Reading the resulting enumeration will consume elements from the stream. This is the preferred manner of converting from a stream to any other data structure.
Convert an enumeration to a stream. Reading the resulting stream will consume elements from the enumeration. This is the preferred manner of creating a stream.
map2 f streama streamb applies f in turn to elements of corresponding positions from streama and streamb. The results are constructed in the same order as a stream. If one stream is short, excess elements of the longer stream are ignored.
scanl f init stream returns a stream of successive reduced values from the left: scanl f init [< 'e0; 'e1; ... >] is equivalent to [< 'init; '(f init e0); '(f (f init e0) e1); ... >]
scan is similar to scanl but without the init value: scanl f init [< 'e0; 'e1; 'e2; ... >] is equivalent to [< 'e0; '(f e0 e1); '(f (f e0 e1) e2); ... >]
dup stream returns a pair of streams which are identical to stream. Note that stream is a destructive data structure, the point of dup is to return two streams can be used independently.
NOT IMPLEMENTED CORRECTLY - WILL RAISE Failure UNTIL CORRECT IMPLEMENTATION FOUND
comb transform a pair of stream into a stream of pairs of corresponding elements. If one stream is short, excess elements of the longer stream are ignored.
merge test (streama, streamb) merge the elements from streama and streamb into a single stream. The bool type here represents the id of the two input streams where true is the first and false represents the second. The test function is applied to each element of the output stream together with the id of the input stream from which it was extracted, to decide which stream should the next element come from. The first element is always taken from streama. When a stream runs out of elements, the merge process will continue to take elements from the other stream until both streams reach their ends.
switch test stream split stream into two streams, where the first stream have all the elements satisfying test, the second stream is opposite. The order of elements in the source stream is preserved.
Note This module is provided essentially for backwards-compatibility. If you feel like using Stream.t, please take a look at BatEnum or LazyList and GenParser.