One way to describe it is that it brings the extensibility of collectors to the intermediate stages of the stream. Another is that it's roughly Clojure's transducers rephrased in Java. I had a go at doing that myself, but it's just not possible to do a great job of it without modifying Stream - which this JEP can do!
Can someone give and example of when to use the gather (say the fold example) vs a collector with reduce? I get that one is terminal operation, vs chain-able through the stream but trying to see the advantage of the gatherer in this case.
A gatherer transforms a stream into a different stream, it cannot be used for reducing, except for some weird and contrived ways I guess, like in the example they gave ("Example: A parallelizable gatherer").
27
u/tomwhoiscontrary Mar 19 '24
I'd completely missed that 461: Stream Gatherers (Preview) existed. This is great!
One way to describe it is that it brings the extensibility of collectors to the intermediate stages of the stream. Another is that it's roughly Clojure's transducers rephrased in Java. I had a go at doing that myself, but it's just not possible to do a great job of it without modifying Stream - which this JEP can do!