Sink.collection
Collect all values emitted from the stream into a collection.Operator only available in the Scala API. The closest operator in the Java API is Sink.seq
.
Signature
Sink.collection
Sink.collection
Description
Collect values emitted from the stream into an arbitrary collection That
. The resulting collection is available through a Future[That]
or when the stream completes. Note that the collection boundaries are those defined in the CanBuildFrom
associated with the chosen collection. See The Architecture of Scala 2.13’s Collections for more info. The seq
operator is a shorthand for Sink.collection[T, Vector[T]]
.
Example
This example reads the numbers from a source and stores them in the List collection.
- Scala
-
source
val source = Source(1 to 5) val result: Future[List[Int]] = source.runWith(Sink.collection[Int, List[Int]]) result.foreach(println) //List(1, 2, 3, 4, 5)
Reactive Streams semantics
cancels If too many values are collected