Hunting with Stream Gatherers
summary
Java adds an intermediate-operation extension point in preview (Stream Gatherers in Java 22/23) that can keep state, emit zero-or-many outputs, short-circuit and run concurrently. The demo builds a unique-by-length gatherer and an n‑gram gatherer (initializer, integrator, combiner, finisher) that replace collect-then-postprocess patterns and avoid mapping every element. Using mapConcurrent with virtual threads runs 100 blocking tasks in ~1s versus ~9s on a 12‑core ForkJoin parallel run, and the custom gatherers work as shown.
AI-written summary · about
chapters (11)
- 0:00Introduction to Streams
- 5:55Streams Evolution
- 8:50Challenges in Stream API
- 15:35Introducing Stream Gatherers
- 18:43Implementing a Gatherer
- 22:37Formal Gatherer Definition
- 26:10Built-in Gatherers
- 27:35Solving Blocking I/O
- 33:36Gatherer Examples
- 37:38Observability and N-grams
- 44:30Conclusion
related talks
45mHunting with Stream Gatherers
40mStream Gathers - The biggest change to Java Streams since 10 years
48mWe Are All Gathered — We Are All to Gather
43mStream Gatherers - Deep Dive with the Expert
45mStream Gatherers
44mLevel Up Your Java Streams with Gatherers
46mJEP 461: Breathing New Life into Java Stream API
52mThe Gatherer API: the tool that was missing in the Stream API
