Skip to content

Missing Stream API functionality you always longed for - provided via Stream API Gatherers

License

Notifications You must be signed in to change notification settings

pivovarit/more-gatherers

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

69 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

more-gatherers

Missing Stream API functionality you always longed for - provided via Gatherers

build pitest Maven Central Version

Stargazers over time

Project is under intense development and will be released alongside Java 24, when Stream Gatherers go GA (hopefully)

Overview

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
  • MoreGatherers.sampling(int)
    • takes every n-th element from the stream
  • MoreGatherers.zip(Iterator<T2>)
    • zips Stream elements with elements from the provided Iterator
  • MoreGatherers.zip(Iterator<T2>, BiFunction<T1,T2>)
    • zips Stream elements with elements from the provided Iterator using a custom zipper function
  • MoreGatherers.zip(Stream<T2>)
    • zips Stream elements with elements from the provided Stream
  • MoreGatherers.zip(Stream<T2>, BiFunction<T1,T2>)
    • zips Stream elements with elements from the provided Stream using a custom zipper function
  • MoreGatherers.zipWithIterable(Iterable<T2>)
    • zips Stream elements with elements from the provided Iterable
  • MoreGatherers.zipWithIterable(Iterable<T2>, BiFunction<T1,T2>)
    • zips elements with elements from the provided Iterable using a custom zipper function
  • MoreGatherers.zipWithIndex()
    • zips Stream elements with their index
  • MoreGatherers.zipWithIndex(BiFunction<Long,T>)
    • zips Stream elements with their index using a custom zipper function
  • 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
  • MoreGatherers.byIndex(BiPredicate<Long, T>)
    • filters elements based on their index and value

Philosophy

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.

About

Missing Stream API functionality you always longed for - provided via Stream API Gatherers

Topics

Resources

License

Code of conduct

Stars

Watchers

Forks

Releases

No releases published

Sponsor this project

 

Languages