grouped
Accumulate incoming events until the specified number of elements have been accumulated and then pass the collection of elements downstream.
Signature
Description
Accumulate incoming events until the specified number of elements have been accumulated and then pass the collection of elements downstream.
See also:
- groupedWeighted for a variant that groups based on element weight
- groupedWithin for a variant that groups based on number of elements and a time window
- groupedWeightedWithin for a variant that groups based on element weight and a time window
Examples
The below example demonstrates how grouped
groups the accumulated elements into Seq
and maps with other operation.
- Scala
-
source
Source(1 to 7).grouped(3).runForeach(println) // Vector(1, 2, 3) // Vector(4, 5, 6) // Vector(7) Source(1 to 7).grouped(3).map(_.sum).runForeach(println) // 6 (= 1 + 2 + 3) // 15 (= 4 + 5 + 6) // 7 (= 7)
- Java
Reactive Streams semantics
emits when the specified number of elements has been accumulated or upstream completed
backpressures when a group has been assembled and downstream backpressures
completes when upstream completes