groupedAdjacentByWeighted

Partitions this stream into chunks by a delimiter function and a weight limit.

Simple operators

Signature

Source.groupedAdjacentByWeightedSource.groupedAdjacentByWeighted Flow.groupedAdjacentByWeightedFlow.groupedAdjacentByWeighted

Description

Partitions this stream into chunks by a delimiter function.

See also:

Examples

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

Scala
sourceSource(List("Hello", "HiHi", "Hi", "Hi", "Greetings", "Hey"))
  .groupedAdjacentByWeighted(_.head, 4)(_.length)
  .runForeach(println)
// prints:
// Vector(Hello)
// Vector(HiHi)
// Vector(Hi, Hi)
// Vector(Greetings)
// Vector(Hey)
Java
sourceSource.from(Arrays.asList("Hello", "HiHi", "Hi", "Hi", "Greetings", "Hey"))
    .groupedAdjacentByWeighted(str -> str.charAt(0), 4, str -> (long) str.length())
    .runForeach(System.out::println, system);
// prints:
// [Hello]
// [HiHi]
// [Hi, Hi]
// [Greetings]
// [Hey]

Reactive Streams semantics

emits when the delimiter function returns a different value than the previous element’s result, or exceeds the maxWeight.

backpressures when a chunk has been assembled and downstream backpressures

completes when upstream completes