<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-2022-jp">
<style type="text/css" style="display:none;"> P {margin-top:0;margin-bottom:0;} </style>
</head>
<body dir="ltr">
<div style="line-height: 18px; white-space: pre; font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
Hi Anthony,</div>
<div style="line-height: 18px; white-space: pre; font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div style="line-height: 18px; white-space: pre; font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);" class="elementToProof">
Thank you for your patience, and for providing feedback, it is always much appreciated.</div>
<div style="line-height: 18px; white-space: pre; font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
<br>
</div>
<div style="line-height: 18px; white-space: pre; font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
>When writing factory methods for Gatherers, there's sometimes a</div>
<div style="line-height: 18px; white-space: pre; font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
degenerate case that requires returning a no-op Gatherer. So I'd like a</div>
<div style="line-height: 18px; white-space: pre; font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
way to mark a no-op Gatherer as such, allowing the Stream implementation</div>
<div style="line-height: 18px; white-space: pre; font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
to recognize and eliminate it from the pipeline. One idea is to add</div>
<div style="line-height: 18px; white-space: pre; font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
Gatherer.defaultIntegrator(), analogous to the other default$B!D(B methods.</div>
<div style="line-height: 18px; white-space: pre; font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
Another is to add Gatherers.identity(), analogous to Function.identity().</div>
<div style="line-height: 18px; white-space: pre; font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div style="line-height: 18px; white-space: pre; font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
I contemplated adding that but in the end I decided I didn't want to add it for the sake of adding it,</div>
<div style="line-height: 18px; white-space: pre; font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
but rather adding it in case it was deemed necessary.</div>
<div style="line-height: 18px; white-space: pre; font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div style="line-height: 18px; white-space: pre; font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
Do you have a concrete use-case (code) that you could share?</div>
<div style="line-height: 18px; white-space: pre; font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div style="line-height: 18px; white-space: pre; font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
>Sometimes a factory method returns a Gatherer that only works correctly</div>
<div style="line-height: 18px; white-space: pre; font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
if the upstream has certain characteristics, for example</div>
<div style="line-height: 18px; white-space: pre; font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
Spliterator.SORTED or Spliterator.DISTINCT.</div>
<div style="line-height: 18px; white-space: pre; font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div style="line-height: 18px; white-space: pre; font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
Do you have a concrete use-case (code) that you could share?</div>
<div style="line-height: 18px; white-space: pre; font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div style="line-height: 18px; white-space: pre; font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
>One idea is to add methods</div>
<div style="line-height: 18px; white-space: pre; font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
like Gatherers.sorted() and Gatherers.distinct(), where the Stream</div>
<div style="line-height: 18px; white-space: pre; font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
implementation would be able to recognize and eliminate these from the</div>
<div style="line-height: 18px; white-space: pre; font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
pipeline if the upstream already has these characteristics. That way</div>
<div style="line-height: 18px; white-space: pre; font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
we'd be able to write `return Gatherers.sorted().andThen($B!D(B);`. Another</div>
<div style="line-height: 18px; white-space: pre; font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
idea is to provide a Gatherer with a way to inspect the upstream</div>
<div style="line-height: 18px; white-space: pre; font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
characteristics. If the upstream is missing the required</div>
<div style="line-height: 18px; white-space: pre; font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
characteristic(s), it could then throw an IllegalStateException.</div>
<div style="line-height: 18px; white-space: pre; font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div style="line-height: 18px; white-space: pre; font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
For a rather long time Gatherer had characteristics, however,</div>
<div style="line-height: 18px; white-space: pre; font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
what I noticed is that given composition of Gatherers what ended up happening</div>
<div style="line-height: 18px; white-space: pre; font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
almost always was that the combination of characteristics added overhead and devolved into the empty set</div>
<div style="line-height: 18px; white-space: pre; font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
real fast.</div>
<div style="line-height: 18px; white-space: pre; font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div style="line-height: 18px; white-space: pre; font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
Also, when it comes to things like sorted() and distinct(), they (by necessity) have to get processed in full</div>
<div style="line-height: 18px; white-space: pre; font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
before emitting anything downstream, which creates a lot of extra memory allocation and doesn't lend themselves all that well to any depth-first streaming.</div>
<div style="line-height: 18px; white-space: pre; font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div style="line-height: 18px; white-space: pre; font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
>The returns clause of Gatherer.Integrator::integrate just states "true</div>
<div style="line-height: 18px; white-space: pre; font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
if subsequent integration is desired, false if not". In particular, it</div>
<div style="line-height: 18px; white-space: pre; font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
doesn't document the behavior I'm observing, that returning false also</div>
<div style="line-height: 18px; white-space: pre; font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
causes downstream to reject any further output elements.</div>
<div style="line-height: 18px; white-space: pre; font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div style="line-height: 18px; white-space: pre; font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
Do you have a test case? (There was a bug fixed in this area after 22 was released, so you may want to test it on a 23-ea)</div>
<div style="line-height: 18px; white-space: pre; font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
<br>
</div>
<div class="elementToProof" style="font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div class="elementToProof" style="font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div id="Signature" style="color: inherit;">
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
Cheers,<br>
$B"e(B</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<b><br>
</b></div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<b>Viktor Klang</b></div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
Software Architect, Java Platform Group<br>
Oracle</div>
</div>
<div id="appendonsend"></div>
<hr style="display:inline-block;width:98%" tabindex="-1">
<div id="divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" style="font-size:11pt" color="#000000"><b>From:</b> core-libs-dev <core-libs-dev-retn@openjdk.org> on behalf of Anthony Vanelverdinghe <dev@anthonyv.be><br>
<b>Sent:</b> Saturday, 27 July 2024 08:57<br>
<b>To:</b> core-libs-dev@openjdk.org <core-libs-dev@openjdk.org><br>
<b>Subject:</b> Stream Gatherers (JEP 473) feedback</font>
<div> </div>
</div>
<div class="BodyFragment"><font size="2"><span style="font-size:11pt;">
<div class="PlainText">When writing factory methods for Gatherers, there's sometimes a
<br>
degenerate case that requires returning a no-op Gatherer. So I'd like a <br>
way to mark a no-op Gatherer as such, allowing the Stream implementation <br>
to recognize and eliminate it from the pipeline. One idea is to add <br>
Gatherer.defaultIntegrator(), analogous to the other default$B!D(B methods. <br>
Another is to add Gatherers.identity(), analogous to Function.identity().<br>
<br>
Sometimes a factory method returns a Gatherer that only works correctly <br>
if the upstream has certain characteristics, for example <br>
Spliterator.SORTED or Spliterator.DISTINCT. One idea is to add methods <br>
like Gatherers.sorted() and Gatherers.distinct(), where the Stream <br>
implementation would be able to recognize and eliminate these from the <br>
pipeline if the upstream already has these characteristics. That way <br>
we'd be able to write `return Gatherers.sorted().andThen($B!D(B);`. Another <br>
idea is to provide a Gatherer with a way to inspect the upstream <br>
characteristics. If the upstream is missing the required <br>
characteristic(s), it could then throw an IllegalStateException.<br>
<br>
The returns clause of Gatherer.Integrator::integrate just states "true <br>
if subsequent integration is desired, false if not". In particular, it <br>
doesn't document the behavior I'm observing, that returning false also <br>
causes downstream to reject any further output elements.<br>
<br>
In the Implementation Requirements section of Gatherer, rephrasing <br>
"Outputs and state later in the input sequence will be discarded if <br>
processing an earlier partition short-circuits." to something like the <br>
following would be clearer to me: "As soon as any partition <br>
short-circuits, the whole Gatherer short-circuits. The state of other <br>
partitions is discarded, i.e. there are no further invocations of the <br>
combiner. The finisher is invoked with the short-circuiting partition's <br>
state." I wouldn't mention discarding of outputs, since that's implied <br>
by the act of short-circuiting.<br>
<br>
Anthony<br>
<br>
</div>
</span></font></div>
</body>
</html>