groupedAdjacentBy
Partitions this stream into chunks by a delimiter function.
Signature
Source.groupedAdjacentBySource.groupedAdjacentBy Flow.groupedAdjacentByFlow.groupedAdjacentBy
Description
Partitions this stream into chunks by a delimiter function.
Adheres to the ActorAttributes.SupervisionStrategy attribute (applied to the key function). On Supervision.Resume the offending element is skipped; on Supervision.Restart the current group is dropped.
See also:
- groupedAdjacentByWeighted for a variant that groups with weight limit too.
Examples
The example below demonstrates how groupedAdjacentBy partitions the elements into Seq List.
- Scala
-
source
Source(List("Hello", "Hi", "Greetings", "Hey")) .groupedAdjacentBy(_.head) .runForeach(println) // prints: // Vector(Hello, Hi) // Vector(Greetings) // Vector(Hey) - Java
-
source
Source.from(List.of("Hello", "Hi", "Greetings", "Hey")) .groupedAdjacentBy(str -> str.charAt(0)) .runForeach(System.out::println, system); // prints: // [Hello, Hi] // [Greetings] // [Hey]
Reactive Streams semantics
emits when the delimiter function returns a different value than the previous element’s result
backpressures when a chunk has been assembled and downstream backpressures
completes when upstream completes
2.0.0-M3+142-ba462fb3*