This documentation regards version 2.10.0+33-49b0d6c8-SNAPSHOT, however the current version is 2.10.0.
Sink.reduce
Apply a reduction function on the incoming elements and pass the result to the next invocation.
Signature
Description
Apply a reduction function on the incoming elements and pass the result to the next invocation. The first invocation receives the two first elements of the flow.
Materializes into a Future
that will be completed by the last result of the reduction function.
Example
- Scala
-
source
val source = Source(1 to 10) val result = source.runWith(Sink.reduce[Int]((a, b) => a + b)) result.map(println)(system.dispatcher) // will print // 55
- Java
Reactive Streams semantics
cancels never
backpressures when the previous reduction function invocation has not yet completed