sealed trait Spool[+A] extends AnyRef
Note: Spool is no longer the recommended asynchronous stream abstraction. We encourage you to use AsyncStream instead. See Spools for the Java adaptation of the Spool companion object.
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.{*::, **:: }}} )
def fill(rest: Promise[Spool[Int]]) { asyncProcess foreach { result => if (result.last) { rest() = Return(result **:: Spool.empty) } else { val next = new Promise[Spool[Int]] rest() = Return(result *:: next) fill(next) } } } val rest = new Promise[Spool[Int]] fill(rest) firstElem *:: rest
explicitly (ie: {{import Spool.{*::, **:: }}}
def fill(rest: Promise[Spool[Int]]) { asyncProcess foreach { result => if (result.last) { rest() = Return(result **:: Spool.empty) } else { val next = new Promise[Spool[Int]] rest() = Return(result *:: next) fill(next) } } } val rest = new Promise[Spool[Int]] fill(rest) firstElem *:: rest
- Alphabetic
- By Inheritance
- Spool
- AnyRef
- Any
- Hide All
- Show All
- Public
- Protected
Abstract Value Members
Concrete Value Members
- final def !=(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
- final def ##: Int
- Definition Classes
- AnyRef → Any
- def ++[B >: A](that: => Future[Spool[B]]): Future[Spool[B]]
Concatenates two spools.
- def ++[B >: A](that: => Spool[B]): Spool[B]
Concatenates two spools.
- final def ==(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
- final def asInstanceOf[T0]: T0
- Definition Classes
- Any
- def clone(): AnyRef
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.CloneNotSupportedException]) @native()
- def collect[B](f: PartialFunction[A, B]): Future[Spool[B]]
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.
- def concat[B >: A](that: Future[Spool[B]]): Future[Spool[B]]
- See also
operator ++
- def concat[B >: A](that: Spool[B]): Spool[B]
- See also
operator ++
- def distinctBy[B](fn: (A) => B): Spool[A]
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
- final def eq(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
- def equals(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef → Any
- def filter(f: (A) => Boolean): Future[Spool[A]]
- def finalize(): Unit
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.Throwable])
- def flatMap[B](f: (A) => Future[Spool[B]]): Future[Spool[B]]
Applies a function that generates a spool for each element in this spool, flattening the result into a single spool.
- def foldLeft[B](z: B)(f: (B, A) => B): Future[B]
- def force: Future[Unit]
Eagerly executes all computation represented by this Spool (presumably for side-effects), and returns a Future representing its completion.
- def foreach[B](f: (A) => B): Future[Unit]
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.
- def foreachElem[B](f: (Option[A]) => B): Future[Unit]
A version of {{foreach}} that wraps each element in an {{Option}}, terminating the stream (EOF) with {{None}}.
- final def getClass(): Class[_ <: AnyRef]
- Definition Classes
- AnyRef → Any
- Annotations
- @native()
- def hashCode(): Int
- Definition Classes
- AnyRef → Any
- Annotations
- @native()
- def headOption: Option[A]
The first element of the spool if it is non-empty.
- final def isInstanceOf[T0]: Boolean
- Definition Classes
- Any
- def map[B](f: (A) => B): Spool[B]
- def mapFuture[B](f: (A) => Future[B]): Future[Spool[B]]
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.
- final def ne(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
- final def notify(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native()
- final def notifyAll(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native()
- def reduceLeft[B >: A](f: (B, A) => B): Future[B]
- final def synchronized[T0](arg0: => T0): T0
- Definition Classes
- AnyRef
- def take(n: Int): Spool[A]
Take the first n elements of the Spool as another Spool (adapted from Stream.take)
- def takeWhile(f: (A) => Boolean): Spool[A]
Take elements from the head of the Spool (lazily), while the given condition is true.
- def toSeq: Future[Seq[A]]
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.
- def toString(): String
- Definition Classes
- AnyRef → Any
- final def wait(): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException])
- final def wait(arg0: Long, arg1: Int): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException])
- final def wait(arg0: Long): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException]) @native()
- def zip[B](that: Spool[B]): Spool[(A, B)]
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