Missing Stream API functionality you always longed for - provided via Gatherers
Project is under intense development and will be released alongside Java 24, when Stream Gatherers go GA (hopefully)
Java's Stream API is a powerful tool for processing collections of data. However, it lacks some functionality that could make it even more powerful. This library aims to fill that gap by providing a set of Gatherers
that can be used to collect data from a stream more flexibly.
Whenever possible, the library follows Project Reactor's naming conventions.
Provided Gatherers
:
MoreGatherers.last(int)
- takes last
n
elements from the stream
- takes last
MoreGatherers.sampling(int)
- takes every
n
-th element from the stream
- takes every
MoreGatherers.zip(Iterator<T2>)
- zips
Stream
elements with elements from the providedIterator
- zips
MoreGatherers.zip(Iterator<T2>, BiFunction<T1,T2>)
- zips
Stream
elements with elements from the providedIterator
using a custom zipper function
- zips
MoreGatherers.zip(Stream<T2>)
- zips
Stream
elements with elements from the providedStream
- zips
MoreGatherers.zip(Stream<T2>, BiFunction<T1,T2>)
- zips
Stream
elements with elements from the providedStream
using a custom zipper function
- zips
MoreGatherers.zipWithIterable(Iterable<T2>)
- zips
Stream
elements with elements from the providedIterable
- zips
MoreGatherers.zipWithIterable(Iterable<T2>, BiFunction<T1,T2>)
- zips elements with elements from the provided
Iterable
using a custom zipper function
- zips elements with elements from the provided
MoreGatherers.zipWithIndex()
- zips
Stream
elements with their index
- zips
MoreGatherers.zipWithIndex(BiFunction<Long,T>)
- zips
Stream
elements with their index using a custom zipper function
- zips
MoreGatherers.distinctBy(Function<T, R>)
- takes distinct elements based on a key extractor function
MoreGatherers.distinctByKeepLast(Function<T, R>)
- takes distinct elements based on a key extractor function, keeping the last occurrence
MoreGatherers.distinctUntilChanged()
- takes elements until a change is detected
MoreGatherers.distinctUntilChanged(Function<T, R>)
- takes elements until a change is detected based on a key extractor function
MoreGatherers.windowSliding(int, int)
- creates a sliding window of a fixed size with a fixed step, extends
Gatherers.windowSliding(int)
by adding a step parameter
- creates a sliding window of a fixed size with a fixed step, extends
MoreGatherers.filteringByIndex(BiPredicate<Long, T>)
- filters elements based on their index and value
The primary goal of this library is to complement the existing Stream API by providing functionality that's currently missing without duplicating features already available. While it is technically possible to create numerous custom Gatherers, this library focuses on offering only those that cannot be easily achieved using standard Stream API operations.
The library is designed to be as lightweight as possible, with no external dependencies. It's implemented using core Java libraries and follows the same conventions as the standard Stream API, drawing inspiration from Project Reactor's method names.