Missing Stream API functionality you always longed for—provided via Gatherers.
Every method returns a Gatherer you can plug directly into .gather(). Grouped by functionality.
Map.Entry<T1, T2>.Map.Entry<T1, T2>.Map.Entry<T1, T2>.Map.Entry<T, Long>.Gatherers.windowSliding(int).Drop a Gatherer into any .gather() call. That's it.
Stream.of(1, 2, 3, 4, 5) .gather(MoreGatherers.last(3)) .toList(); // [3, 4, 5]
Stream.of("a", "b", "c") .gather(MoreGatherers.zipWithIndex()) .toList(); // [a=0, b=1, c=2]
Stream.of(1, 1, 2, 2, 3, 1) .gather(MoreGatherers.distinctUntilChanged()) .toList(); // [1, 2, 3, 1]
Stream.of(1, 2, 3, 4, 5) .gather(MoreGatherers.sampling(2)) .toList(); // [1, 3, 5]
Stream.of(1, 2, 3, 4, 5) .gather(MoreGatherers.windowSliding(3, 2)) .toList(); // [[1, 2, 3], [3, 4, 5]]
Stream.of("a", "b", "c") .gather(MoreGatherers.zip(Stream.of(1, 2, 3))) .toList(); // [a=1, b=2, c=3]
Stream.of(1, 2, 3, 4, 5, 6) .gather(MoreGatherers.groupingBy(i -> i % 2 == 0 ? "even" : "odd")) .toList(); // [odd=[1, 3, 5], even=[2, 4, 6]]
Stream.of("a", "b", "c", "d", "e") .gather(MoreGatherers.filteringByIndex((idx, val) -> idx % 2 == 0)) .toList(); // ["a", "c", "e"]
Requires Java 24+. Available on Maven Central.
<dependency> <groupId>com.pivovarit</groupId> <artifactId>more-gatherers</artifactId> <version>0.2.0</version> </dependency>
implementation 'com.pivovarit:more-gatherers:0.2.0'
implementation("com.pivovarit:more-gatherers:0.2.0")
What guides the design of this library.