Legend:
Library
Module
Module type
Parameter
Class
Class type
An immutable sequence of values, with a possibly incomplete tail that may be extended asynchronously.
For most applications one should use Pipe instead of Stream. One justifiable usage of Stream rather than Pipe is in single-writer, multi-consumer (multicast) scenarios where pushback is not required.
The basic primitive operation for getting the next element out of stream is Stream.next, which (asynchronously) returns the element and the rest of the stream.
create f returns a stream t and calls f tail, where the elements of the stream are determined as the tail is extended, and the end of the stream is reached when the tail is closed.
next t returns a deferred that will become determined when the next part of the stream is determined. This is Cons (v, t'), where v is the next element of the stream and t' is the rest of the stream, or with Nil at the end of the stream.
copy_to_tail t tail reads elements from t and puts them in tail, until the end of t is reached.
Sequence operations ---------------------------------------------------------------------- There are the usual sequence operations:
append, fold, iter, map, filter_map, take
There are also deferred variants:
iter', map', filter_map'
These take anonymous functions that return deferreds generalizing the usual sequence operation and allowing the client to control the rate at which the sequence is processed.
concat t takes a stream of streams and produces a stream that is the concatenation of each stream in order (you see all of stream 1, then all of stream 2... etc.)
fold' t ~init ~f is like list fold, walking over the elements of the stream in order, as they become available. fold' returns a deferred that will yield the final value of the accumulator, if the end of the stream is reached.
val fold : 'at->init:'b->f:('b->'a->'b)->'bDeferred.t
fold t ~init ~f is a variant of fold' in which f does not return a deferred.
iter' t ~f applies f to each element of the stream in turn, as they become available. It continues onto the next element only after the deferred returned by f becomes determined.
iter_durably' t ~f is like iter' t ~f, except if f raises an exception it continues with the next element of the stream *and* reraises the exception (to the monitor in scope when iter_durably was called).
iter_durably t ~f is like iter t ~f, except if f raises an exception it continues with the next element of the stream *and* reraises the exception (to the monitor in scope when iter_durably was called).
iter_durably_report_end t ~f is equivalent to iter_durably' t ~f:(fun x -> return
(f x)) but it is more efficient
interleave list takes a stream of streams and returns a stream of their items interleaved as they become determined. The interleaved stream will be closed when the outer stream and all of the inner streams have been closed.