An immutable sequence of values, with a possibly incomplete tail that may be extended asynchronously.
For most applications one should use [root: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.
Streams can be converted to and from lists. Although, conversion to a list returns a deferred, because the stream is determined asynchronously.
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.
iter t ~f
= don't_wait_for (iter' t ~f:(fun a -> f a; Deferred.unit))
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
split ~stop ~f t
returns a pair (p, d)
, where p
is a prefix of t
that ends
for one of three reasons:
1. [t] ends 2. stop becomes determined 3. f returns `Found
The deferred d
describes why the prefix ended, and returns the suffix of the
stream in case (2) or (3).