Stream Gatherers in Java: The Stream API Finally Learned to Window, Scan, and Fold
Since Java 8, the Stream API has had an asymmetry: terminal operations were extensible — collect(Collector) lets you define any summary you like — but intermediate operations were a fixed menu. If you wanted windows, running totals, or distinct-by-key in the middle of a pipeline, you either broke out of the pipeline into a loop, or bent a Collector into doing an intermediate operation’s job. Stream Gatherers close that gap. Stream.gather(Gatherer) is to intermediate operations what collect(Collector) is to terminal operations — that framing is JEP 485’s own, and it is the fastest way to understand the feature. ...