Compact removes "pauses" in the stream (represented as Wait(_) nodes).
Compact removes "pauses" in the stream (represented as Wait(_) nodes).
Normally, Wait(_) values are used to defer tail computation in cases where it is convenient to return a stream value where neither the head or tail are computed yet.
In some cases (particularly if the stream is to be memoized) it may be desirable to ensure that these values are not retained.
Lazily concatenate two streams.
Lazily concatenate two streams.
In this case the evaluation of the second stream may be deferred.
Lazily concatenate two streams.
Lazily concatenate two streams.
Return a stream consisting of all but the first n
elements of
this stream.
Return a stream consisting of all but the first n
elements of
this stream.
If the current stream has n
or fewer elements, an empty stream
will be returned.
From the beginning of this stream, create a new stream which
removes all elements that fulfill the predicate f
.
From the beginning of this stream, create a new stream which
removes all elements that fulfill the predicate f
. Once an
element is found which does not fulfill the predicate, that
element and all subsequent elements will be returned.
If all elements satisfy f
, an empty stream will be returned.
If no elements satisfy f
, the current stream will be returned.
For example:
Streaming(1, 2, 3, 4, 5, 6, 7).takeWhile(n => n != 4)
Will result in: Streaming(4, 5, 6, 7)
Return true if some element of the stream satisfies the predicate, false otherwise.
Return true if some element of the stream satisfies the predicate, false otherwise.
Lazily filter the stream given the predicate f
.
Lazily filter the stream given the predicate f
.
Eagerly search the stream from the left.
Eagerly search the stream from the left. The search ends when f returns true for some a, or the stream is exhausted. Some(a) signals a match, None means no matching items were found.
Lazily transform the stream given a function f
.
Lazily transform the stream given a function f
.
The stream's catamorphism.
The stream's catamorphism.
This method allows the stream to be transformed into an arbitrary value by handling two cases:
This method can be more convenient than pattern-matching, since it includes support for handling deferred streams (i.e. Wait(_)), these nodes will be evaluated until an empty or non-empty stream is found (i.e. until Empty() or Cons() is found).
Eagerly fold the stream to a single value from the left.
Eagerly fold the stream to a single value from the left.
Lazily fold the stream to a single value from the right.
Lazily fold the stream to a single value from the right.
A variant of fold, used for constructing streams.
A variant of fold, used for constructing streams.
The only difference is that foldStream will preserve deferred streams. This makes it more appropriate to use in situations where the stream's laziness must be preserved.
Return true if every element of the stream satisfies the predicate, false otherwise.
Return true if every element of the stream satisfies the predicate, false otherwise.
Interleave the elements of two streams.
Interleave the elements of two streams.
Given x = [x0, x1, x2, ...] and y = [y0, y1, y2, ...] this method will return the stream [x0, y0, x1, y1, x2, ...]
If one stream is longer than the other, the rest of its elements will appear after the other stream is exhausted.
Return true if the stream is empty, false otherwise.
Return true if the stream is empty, false otherwise.
In this case of deferred streams this will force the first element to be calculated.
Provide an iterator over the elements in the stream.
Provide an iterator over the elements in the stream.
Lazily zip two streams together using Ior.
Lazily zip two streams together using Ior.
Unlike zip
, the length of the result will be the longer of the
two arguments.
Zip two streams together, using the given function f
to produce
the output values.
Zip two streams together, using the given function f
to produce
the output values.
Unlike zipMap, the length of the result will be the *longer* of
the two input streams. The functions g
and h
will be used in
this case to produce valid C
values.
The expression:
(lhs izipMap rhs)(f, g, h)
is equivalent to (but more efficient than):
(lhs izip rhs).map { case Ior.Both(a, b) => f(a, b) case Ior.Left(a) => g(a) case Ior.Right(b) => h(b) }
Lazily transform the stream given a function f
.
Lazily transform the stream given a function f
.
Ensure that repeated traversals of the stream will not cause repeated tail computations.
Ensure that repeated traversals of the stream will not cause repeated tail computations.
By default stream does not memoize to avoid memory leaks when the head of the stream is retained.
Merge two sorted streams into a new stream.
Merge two sorted streams into a new stream.
The streams are assumed to already be sorted. If they are not, the resulting order is not defined.
Return true if the stream is non-empty, false otherwise.
Return true if the stream is non-empty, false otherwise.
In this case of deferred streams this will force the first element to be calculated.
Peek at the start of the stream to see whether we know if it is empty.
Peek at the start of the stream to see whether we know if it is empty.
Unlike .isEmpty/.nonEmpty, this method will not force the calculationg of a deferred stream. Instead, None will be returned.
Produce the Cartestian product of two streams.
Produce the Cartestian product of two streams.
Given x = [x0, x1, x2, ...] and y = [y0, y1, y2, ...] this method will return the stream:
[(x0, y0), (x0, y1), (x1, y0), (x0, y2), (x1, y1), (x2, y0), ...]
This is the diagonalized product of both streams. Every possible combination will (eventually) be reached.
This is true even for infinite streams, at least in theory -- time and space limitations of evaluating an infinite stream may make it impossible to reach very distant elements.
This method lazily evaluates the input streams, but due to the diagonalization method may read ahead more than is strictly necessary.
Provide a stream of all the tails of a stream (including itself).
Provide a stream of all the tails of a stream (including itself).
For example, Streaming(1, 2).tails is equivalent to:
Streaming(Streaming(1, 2), Streaming(1), Streaming.empty)
Return a stream consisting only of the first n
elements of this
stream.
Return a stream consisting only of the first n
elements of this
stream.
If the current stream has n
or fewer elements, the entire
stream will be returned.
From the beginning of this stream, create a new stream which
takes only those elements that fulfill the predicate f
.
From the beginning of this stream, create a new stream which
takes only those elements that fulfill the predicate f
. Once an
element is found which does not fulfill the predicate, no further
elements will be returned.
If all elements satisfy f
, the current stream will be returned.
If no elements satisfy f
, an empty stream will be returned.
For example:
Streaming(1, 2, 3, 4, 5, 6, 7).takeWhile(n => n != 4)
Will result in: Streaming(1, 2, 3)
Provide an array of elements in the stream.
Provide an array of elements in the stream.
This will evaluate the stream immediately, and will hang in the case of infinite streams.
Provide a list of elements in the stream.
Provide a list of elements in the stream.
This will evaluate the stream immediately, and will hang in the case of infinite streams.
String representation of the first n elements of a stream.
String representation of the first n elements of a stream.
Basic string representation of a stream.
Basic string representation of a stream.
This method will not force evaluation of any lazy part of a stream. As a result, you will see at most one element (the first one).
Use .toString(n) to see the first n elements of the stream.
Deconstruct a stream into a head and tail (if available).
Deconstruct a stream into a head and tail (if available).
This method will evaluate the stream until it finds a head and tail, or until the stream is exhausted. The head will be evaluated, whereas the tail will remain (potentially) lazy within Eval.
Unzip this stream of tuples into two distinct streams.
Unzip this stream of tuples into two distinct streams.
Lazily zip two streams together.
Lazily zip two streams together.
The length of the result will be the shorter of the two arguments.
Lazily zip two streams together, using the given function f
to
produce output values.
Lazily zip two streams together, using the given function f
to
produce output values.
The length of the result will be the shorter of the two arguments.
The expression:
(lhs zipMap rhs)(f)
is equivalent to (but more efficient than):
(lhs zip rhs).map { case (a, b) => f(a, b) }
Zip the items of the stream with their position.
Zip the items of the stream with their position.
Indices start at 0, so
Streaming('x, 'y, 'z).zipWithIndex
lazily produces:
Streaming(('x, 0), ('y, 1), ('z, 2))