Concatenates two streams.
Concatenates two streams.
Note: If this stream is infinite, we never process the concatenated stream; effectively: m ++ k == m.
concat for Java users.
++
Returns the suffix of this stream after the first n
elements, or
AsyncStream.empty
if n
is larger than the number of elements in the
stream.
Returns the suffix of this stream after the first n
elements, or
AsyncStream.empty
if n
is larger than the number of elements in the
stream.
Note: this forces all of the intermediate dropped elements.
Given a predicate p
returns the suffix remaining after takeWhile(p)
:
Given a predicate p
returns the suffix remaining after takeWhile(p)
:
AsyncStream(1, 2, 3, 4, 1).dropWhile(_ < 3) = AsyncStream(3, 4, 1) AsyncStream(1, 2, 3).dropWhile(_ < 5) = AsyncStream.empty AsyncStream(1, 2, 3).dropWhile(_ < 0) = AsyncStream(1, 2, 3)
Returns a stream of elements that satisfy the predicate p
.
Returns a stream of elements that satisfy the predicate p
.
Note: forces the stream up to the first element which satisfies the predicate. This operation may block forever on infinite streams in which no elements match.
Map a function f
over the elements in this stream and concatenate the
results.
Concatenate a stream of streams.
Concatenate a stream of streams.
val a = AsyncStream(1) AsyncStream(a, a, a).flatten = AsyncStream(1, 1, 1)
Java users see AsyncStream.flattens.
Applies a binary operator to a start value and all elements of the stream, from head to tail.
Applies a binary operator to a start value and all elements of the stream, from head to tail.
Note: forces the stream. If the stream is infinite, the resulting future is equivalent to Future.never.
the starting value.
a binary operator applied to elements of this stream.
Like foldLeft
, except that its result is encapsulated in a Future.
Like foldLeft
, except that its result is encapsulated in a Future.
foldLeftF
works from head to tail over the stream.
Note: forces the stream. If the stream is infinite, the resulting future is equivalent to Future.never.
the starting value.
a binary operator applied to elements of this stream.
This is a powerful and expert level function.
This is a powerful and expert level function. A fold operation
encapsulated in a Future. Like foldRight on normal lists, it replaces
every cons with the folded function f
, and the empty element with z
.
Note: For clarity, we imagine that surrounding a function with backticks
() allows infix usage.
(1 +:: 2 +:: 3 +:: empty).foldRight(z)(f) = 1 `f` flatMap (2 `f` flatMap (3 `f` z))
Note: if f
always forces the second parameter, for infinite streams the
future never resolves.
the parameter that replaces the end of the list.
a binary operator applied to elements of this stream. Note that the second paramter is call-by-name.
Note: forces the stream.
Note: forces the stream. For infinite streams, the future never resolves.
Maps each element of the stream to a Future action, resolving them from head to tail.
Maps each element of the stream to a Future action, resolving them from head to tail. The resulting Future completes when the action completes for the last element.
Note: forces the stream. For infinite streams, the future never resolves.
Returns the head of this stream if not empty.
Returns true if there are no elements in the stream.
stream.map(f)
is the stream obtained by applying f
to each element of
stream
.
Constructs a new stream by mapping each element of this stream to a Future action, evaluated from head to tail.
Attempts to transform the stream into a Seq, and in the case of failure,
observe
returns whatever was able to be transformed up to the point of
failure along with the exception.
Attempts to transform the stream into a Seq, and in the case of failure,
observe
returns whatever was able to be transformed up to the point of
failure along with the exception. As a result, this Future never fails,
and if there are errors they can be accessed via the Option.
Note: forces the stream. For infinite streams, the future never resolves.
Similar to foldLeft, but produces a stream from the result of each successive fold:
Similar to foldLeft, but produces a stream from the result of each successive fold:
AsyncStream(1, 2, ...).scanLeft(z)(f) == z +:: f(z, 1) +:: f(f(z, 1), 2) +:: ...
Note that for an AsyncStream as
:
as.scanLeft(z)(f).last == as.foldLeft(z)(f)
Note: forces the first element of the tail.
Returns the prefix of this stream of length n
, or the stream itself if
n
is larger than the number of elements in the stream.
Given a predicate p
, returns the longest prefix (possibly empty) of this
stream that satisfes p
:
Given a predicate p
, returns the longest prefix (possibly empty) of this
stream that satisfes p
:
AsyncStream(1, 2, 3, 4, 1).takeWhile(_ < 3) = AsyncStream(1, 2) AsyncStream(1, 2, 3).takeWhile(_ < 5) = AsyncStream(1, 2, 3) AsyncStream(1, 2, 3).takeWhile(_ < 0) = AsyncStream.empty
A Future of the stream realized as a list.
A Future of the stream realized as a list. This future completes when all elements of the stream are resolved.
Note: forces the entire stream. If one asynchronous call fails, it fails the aggregated result.
The head and tail of this stream, if not empty.
The head and tail of this stream, if not empty. Note the tail thunk which preserves the tail's laziness.
empty.uncons == Future.None (a +:: m).uncons == Future.value(Some(a, () => m))
filter
A representation of a lazy (and possibly infinite) sequence of asynchronous values. We provide combinators for non-blocking computation over the sequence of values.
It is composable with Future, Seq and Option.
All of its operations are lazy and don't force evaluation, unless otherwise noted.
The stream is persistent and can be shared safely by multiple threads.