Concatenates two spools.
Concatenates two spools.
The standard Scala collect, in order to implement map & filter.
The standard Scala collect, in order to implement map & filter.
It may seem unnatural to return a Future[…] here, but we cannot know whether the first element exists until we have applied its filter.
operator ++
operator ++
Builds a new Spool from this one by filtering out duplicate elements, elements for which fn returns the same value.
Builds a new Spool from this one by filtering out duplicate elements, elements for which fn returns the same value.
NB: this has space consumption O(N) of the number of distinct items
Applies a function that generates a spool for each element in this spool, flattening the result into a single spool.
Eagerly executes all computation represented by this Spool (presumably for side-effects), and returns a Future representing its completion.
Apply {{f}} for each item in the spool, until the end.
Apply {{f}} for each item in the spool, until the end. {{f}} is applied as the items become available.
A version of {{foreach}} that wraps each element in an {{Option}}, terminating the stream (EOF) with {{None}}.
The first element of the spool if it is non-empty.
Applies a function that generates a Future[B] for each element of this spool.
Applies a function that generates a Future[B] for each element of this spool. The returned future is satisfied when the head of the resulting spool is available.
Take the first n elements of the Spool as another Spool (adapted from Stream.take)
Take elements from the head of the Spool (lazily), while the given condition is true.
Fully buffer the spool to a {{Seq}}.
Fully buffer the spool to a {{Seq}}. The returned future is satisfied when the entire result is ready.
Zips two Spools returning a Spool of Tuple2s.
Zips two Spools returning a Spool of Tuple2s.
If one Spool is shorter, excess elements of the longer Spool are discarded.
c.f. scala.collection.immutable.Stream#zip
A spool is an asynchronous stream. It more or less mimics the scala {{Stream}} collection, but with cons cells that have either eager or deferred tails.
Construction of eager Spools is done with either Spool.cons or the {{**::}} operator. To construct a lazy/deferred Spool which materializes its tail on demand, use the {{*::}} operator. In order to use these operators for deconstruction, they must be imported explicitly (ie: {{import Spool.{*::, **:: }}} )
Note: There is a Java-friendly API for this trait: com.twitter.concurrent.AbstractSpool.
explicitly (ie: {{import Spool.{*::, **:: }}}
Note: There is a Java-friendly API for this trait: com.twitter.concurrent.AbstractSpool.