groupedAdjacentBy
Partitions this stream into chunks by a delimiter function.
Signature
Source.groupedAdjacentBy
Source.groupedAdjacentBy
Flow.groupedAdjacentBy
Flow.groupedAdjacentBy
Description
Partitions this stream into chunks by a delimiter function.
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(Arrays.asList("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
1.2.0