groupedAdjacentByWeighted
Partitions this stream into chunks by a delimiter function and a weight limit.
Signature
Source.groupedAdjacentByWeighted
Source.groupedAdjacentByWeighted
Flow.groupedAdjacentByWeighted
Flow.groupedAdjacentByWeighted
Description
Partitions this stream into chunks by a delimiter function.
See also:
- groupedAdjacentBy for a simpler variant.
Examples
The example below demonstrates how groupedAdjacentByWeighted
partitions the elements into Seq
List
.
- Scala
-
source
Source(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
-
source
Source.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
1.2.0