Repository navigation
Java 24: Built-in stream gatherers (fold, scan, windowSliding, mapConcurrent) - #104
Merged
mperor merged 1 commit intoOct 27, 2026
Conversation
Test Results280 tests +4 277 ✅ +4 6s ⏱️ ±0s Results for commit 51e8b79. ± Comparison against base commit ae4119f. This pull request skips 1 and un-skips 1 tests. |
mperor
marked this pull request as ready for review
October 27, 2026 07:15
mperor
deleted the
DAILY/91-stream-gatherers-fold-scan-sliding-mapconcurrent
branch
October 27, 2026 19:48
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What you'll learn
Gatherers.windowSlidingoverlaps windows one element at a time, whileGatherers.windowFixedpartitions the stream into non-overlapping chunksGatherers.foldreduces a stream to a single final value without needing an associative/combiner function, unlikeStream.reduceGatherers.scanemits every intermediate accumulated value instead of only the last oneGatherers.mapConcurrentmaps elements concurrently (one virtual thread per element) but still delivers results in the original encounter orderWhy it matters
These are the five built-in gatherers finalized by JEP 485 (Stream Gatherers). Knowing which one partitions, which one overlaps, which one streams intermediate state, and which one parallelizes safely while preserving order saves a trip to the Javadoc when reaching for a custom
Collector/reducealternative.Read more
JEP 485: Stream Gatherers
Quiz
Given
Stream.of(300, 100, 200, 50).gather(Gatherers.mapConcurrent(4, delay -> { sleep(delay); return delay; })), in what order do the results come out?Answer
In input order: 300, 100, 200, 50 - even though the element with delay 50 finishes first. `mapConcurrent` runs the mapper for each element concurrently but buffers completed results so the output stream still respects encounter order.Note: this environment's network policy blocks access to the Foojay/Adoptium JDK download services the Gradle toolchain needs to provision JDK 25, and no JDK 25 is pre-installed, so
:JavaReleases:testcould not be run locally. Opening as a draft; CI (which has JDK 25) will verify. The gatherer APIs used (fold,scan,windowSliding,mapConcurrent) match the finalized JEP 485 signatures and mirror the style of the existingwindowFixed/custom-gatherer tests already in the same file.Closes #91