groupedAdjacentBy

Partitions this stream into chunks by a delimiter function.

Simple operators

Signature

Source.groupedAdjacentBySource.groupedAdjacentBy Flow.groupedAdjacentByFlow.groupedAdjacentBy

Description

Partitions this stream into chunks by a delimiter function.

See also:

Examples

The example below demonstrates how groupedAdjacentBy partitions the elements into Seq List.

Scala
sourceSource(List("Hello", "Hi", "Greetings", "Hey"))
  .groupedAdjacentBy(_.head)
  .runForeach(println)
// prints:
// Vector(Hello, Hi)
// Vector(Greetings)
// Vector(Hey)
Java
sourceSource.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