<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<style type="text/css" style="display:none;"> P {margin-top:0;margin-bottom:0;} </style>
</head>
<body dir="ltr">
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);" class="elementToProof">
<br>
</div>
<div id="appendonsend"></div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<hr tabindex="-1" style="display:inline-block; width:98%">
<div id="divRplyFwdMsg" dir="ltr"><font style="font-size: 11pt; color: rgb(0, 0, 0);" face="Calibri, sans-serif"><b>From:</b> Remi Forax <forax@univ-mlv.fr><br>
<b>Sent:</b> Thursday, 29 June 2023 10:03<br>
<b>To:</b> Viktor Klang <viktor.klang@oracle.com><br>
<b>Cc:</b> core-libs-dev <core-libs-dev@openjdk.org><br>
<b>Subject:</b> [External] : Re: java.util.stream.Stream: API for user-extensible intermediate operations</font>
<div> </div>
</div>
<div>
<div style="font-family: arial, helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<div><br>
</div>
<div><br>
</div>
<hr id="x_zwchr" data-marker="__DIVIDER__">
<div data-marker="__HEADERS__">
<blockquote style="border-left: 2px solid rgb(16, 16, 255); margin-left: 5px; padding-left: 5px; font-weight: normal; font-style: normal; text-decoration: none; font-family: Helvetica, Arial, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<b>From: </b>"Viktor Klang" <viktor.klang@oracle.com><br>
<b>To: </b>"core-libs-dev" <core-libs-dev@openjdk.org><br>
<b>Sent: </b>Tuesday, June 27, 2023 7:10:42 PM<br>
<b>Subject: </b>java.util.stream.Stream: API for user-extensible intermediate operations<br>
</blockquote>
</div>
<div></div>
<div data-marker="__QUOTED_TEXT__" class="elementToProof">
<blockquote data-mce-style="border-left: 2px solid #1010FF; margin-left: 5px; padding-left: 5px; color: #000; font-weight: normal; font-style: normal; text-decoration: none; font-family: Helvetica,Arial,sans-serif; font-size: 12pt;" style="border-left: 2px solid rgb(16, 16, 255); margin-left: 5px; padding-left: 5px; font-weight: normal; font-style: normal; text-decoration: none; font-family: Helvetica, Arial, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<div class="x_elementToProof" data-mce-style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: #000000;" style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
Hi core-libs-dev,</div>
<div class="x_elementToProof" data-mce-style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: #000000;" style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div class="x_elementToProof" data-mce-style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: #000000;" style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
Over the past 6+ months I've been thinking about, and tinkering with, how we'd be able to expose a user-facing API for extensible intermediate java.util.stream.Stream operations¡ªa feature envisioned all the way back when Streams were created.<br>
</div>
<div class="x_elementToProof" data-mce-style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: #000000;" style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div class="x_elementToProof" data-mce-style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: #000000;" style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
I'm now at a point where I have a viable design and implementation, and so I'm turning to you for your feedback: on the direction taken; the API concepts; and, in particular, is there anything which I have overlooked/missed?</div>
</blockquote>
<div><br>
</div>
<div class="elementToProof">>I think this API is overly generic and hard to reason about it, for users and IDEs.
<br>
</div>
<div class="elementToProof"><br>
</div>
<div class="elementToProof">The API is for all intents and purposes Collector with a boolean return type for the accumulator and an added downstream handle parameter added to the accumulator and the finisher.<br>
</div>
<div><br>
</div>
<div class="elementToProof">>The main issue is that the same API is used for both stateless and stateful operations, which means that as a user, we have no idea if a call to stream.gather() is stateful or not.
<br>
</div>
<div class="elementToProof"><br>
</div>
<div class="elementToProof">How is this different from any of the other pre-existing Stream operations?<br>
</div>
<div class="elementToProof"><br>
</div>
<div class="elementToProof">>Which is a departure from the current API that cleanly separate stateless and staful operations. Here, we are left in the dark. In a sense, this API is too powerful, it can do too much thing, so as a user we can not reason about
it.</div>
<div class="elementToProof"><br>
</div>
<div class="elementToProof">A Gatherer encodes it input and output types, in what sense would that not be enough to reason about it?<br>
</div>
<div><br>
</div>
<div class="elementToProof">>I like the idea of a Collector 2.0 i.e. using the Gatherer API at the end of the stream (not in the middle), but currently, the Gatherer API is not a Collector, so we now have two different APIs for doing partially the same job.
I wonder if the Collector API can be retroffitted to act as a Gatherer API, avoiding to have to choose which one to use, a gatherer being the equivalent of a "flat-collector" + short-circuit.</div>
<div class="elementToProof"><br>
</div>
<div class="elementToProof">Collector serves a very important role of being able to get information
<b>out of</b> a Stream and deliver that information in a certain shape, a Gatherer does not provide any facility for this.<br>
</div>
<div class="elementToProof"><br>
</div>
>The idea of unsupportedCombiner() seems out of place, like a patch to be able to clobble different things together. I'm not sure to understand why it's needed for a Gatherer, and why it is not needed for Collectors ?<br>
<div class="elementToProof"><br>
</div>
<div class="elementToProof">Nothing prevents us from treating a `null` combiner the same way. My primary reason for making it a dedicated thing was to be able to differentiate a possible bug (user passing in a null reference inadvertently) from explicitly stating
that a combiner does not exist from this operation.</div>
<div class="elementToProof"><br>
</div>
<div class="elementToProof"><i>unsupportedCombiner()</i> as an artifact can be completely hidden if desired, as
<i>Gatherer.of()</i> can have permutations without specifying a combiner, and the
<i>default method</i> of Gatherer.combiner() could return <i>unsupportedCombiner()</i>. I opted not to do this initially, because I felt like being explicit about not having a combiner means that it is a concious decision by the implementor of the Gatherer.<br>
</div>
<div class="elementToProof"><br>
</div>
<div class="elementToProof"><br data-mce-bogus="1">
</div>
<div class="elementToProof">>So I would prefer that API to extends the current Collector API but not the intermediary operations. Yes, it's less powerful.<br>
</div>
<div class="elementToProof">It means that instead of using one stream with a collect like operation in the middle, users will have to use two streams, one after the other, but it makes the code easier to understand (also having two streams give users better
control on which part should be in parallel).</div>
<div class="elementToProof"><br>
</div>
<div class="elementToProof">That would be something completely different from the goal of providing user-extensible intermediate operations, which is something which this proposal is explicitly trying to address.</div>
<div class="elementToProof"><br>
</div>
<div class="elementToProof">Cheers,</div>
<div class="elementToProof">¡Ì<br>
</div>
<div class="elementToProof"><br>
</div>
<div class="elementToProof">>R¨¦mi<br>
</div>
<div><br>
</div>
<blockquote data-mce-style="border-left: 2px solid #1010FF; margin-left: 5px; padding-left: 5px; color: #000; font-weight: normal; font-style: normal; text-decoration: none; font-family: Helvetica,Arial,sans-serif; font-size: 12pt;" style="border-left: 2px solid rgb(16, 16, 255); margin-left: 5px; padding-left: 5px; font-weight: normal; font-style: normal; text-decoration: none; font-family: Helvetica, Arial, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<div class="x_elementToProof x_ContentPasted0" data-mce-style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: #000000;" style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<div class="x_ContentPasted0 x_elementToProof"><br>
</div>
<div class="x_ContentPasted0 x_elementToProof">(If you, like myself, prefer reading pre-rendered markdown,
<a href="https://cr.openjdk.org/~vklang/Gatherers.html" data-auth="NotApplicable" title="https://cr.openjdk.org/~vklang/Gatherers.html" id="LPlnk689721" data-mce-href="https://cr.openjdk.org/~vklang/Gatherers.html" data-loopstyle="linkonly">
click here</a>)<br>
</div>
</div>
<div><br>
</div>
<div><br>
</div>
</blockquote>
</div>
</div>
</div>
</body>
</html>