Skip to content

Java 24: Built-in stream gatherers (fold, scan, windowSliding, mapConcurrent) - #104

Merged
mperor merged 1 commit into
masterfrom
DAILY/91-stream-gatherers-fold-scan-sliding-mapconcurrent
Oct 27, 2026
Merged

mperor merged 1 commit into
masterfrom
DAILY/91-stream-gatherers-fold-scan-sliding-mapconcurrent

Conversation

@mperor

@mperor mperor commented Oct 27, 2026 •

Copy link
Copy Markdown
Owner

What you'll learn

  • Gatherers.windowSliding overlaps windows one element at a time, while Gatherers.windowFixed partitions the stream into non-overlapping chunks
  • Gatherers.fold reduces a stream to a single final value without needing an associative/combiner function, unlike Stream.reduce
  • Gatherers.scan emits every intermediate accumulated value instead of only the last one
  • Gatherers.mapConcurrent maps elements concurrently (one virtual thread per element) but still delivers results in the original encounter order

Why 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/reduce alternative.

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?

AnswerIn 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:test could 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 existing windowFixed/custom-gatherer tests already in the same file.

Closes #91

@mperor mperor added the daily Queued for the daily learning PR label Oct 27, 2026
@github-actions

Copy link
Copy Markdown

Test Results

280 tests  +4   277 ✅ +4   6s ⏱️ ±0s
 80 suites ±0     3 💤 ±0 
 80 files   ±0     0 ❌ ±0 

Results for commit 51e8b79. ± Comparison against base commit ae4119f.

This pull request skips 1 and un-skips 1 tests.
pl.mperor.lab.java.design.pattern.creational.singleton.SingletonTest ‑ testLazyInitialized()
pl.mperor.lab.java.design.pattern.creational.singleton.SingletonTest ‑ testSerializationSafe()

@mperor
mperor marked this pull request as ready for review October 27, 2026 07:15
@mperor
mperor merged commit 49dc8e5 into master Oct 27, 2026
2 checks passed
@mperor
mperor deleted the DAILY/91-stream-gatherers-fold-scan-sliding-mapconcurrent branch October 27, 2026 19:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

daily Queued for the daily learning PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Java 24: Built-in stream gatherers (fold, scan, windowSliding, mapConcurrent)

2 participants