RFR: 8319123: Implement JEP 461: Stream Gatherers (Preview) [v13]
Svein Otto Solem
svein.otto.solem at gmail.com
Mon Nov 27 23:46:58 UTC 2023
I tried to understand the GathererOp class and came over a small detail concering Gatherer.Integrator.
The two gatheres below are equivalent, both are greedy.
Gatherer.Integrator.Greedy<Void, String, Integer> voidStringIntegerGreedy = (v, s, downStream) -> downStream.push(s.length());
var greedy1 = Gatherer.of(Gatherer.Integrator.ofGreedy(voidStringIntegerGreedy));
var greedy2 = Gatherer.of(Gatherer.Integrator.of(voidStringIntegerGreedy));
Inlining the lambda makes them different.
var greedy = Gatherer.of(Gatherer.Integrator.ofGreedy((v, s, downStream) -> downStream.push(s.length())));
var nonGreedy = Gatherer.of(Gatherer.Integrator.of((v, s, downStream) -> downStream.push(s.length())));
If this can be a problem an introduction of an Integrator subtype like NonGreedy would have given a compiler error on the "var greedy2 =" line instead.
interface Integrator {
.....
static <A, T, R> NonGreedy<A, T, R> of(NonGreedy<A, T, R> integrator) {
return integrator;
}
static <A, T, R> Greedy<A, T, R> ofGreedy(Greedy<A, T, R> greedy) {
return greedy;
}
interface Greedy<A, T, R> extends Integrator<A, T, R> { }
interface NonGreedy<A, T, R> extends Integrator<A, T, R> { }
}
Svein Otto Solem
Retired programmer
Kantega
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/core-libs-dev/attachments/20231127/373c6a8e/attachment-0001.htm>
More information about the core-libs-dev
mailing list