<html><body><div style="font-family: arial, helvetica, sans-serif; font-size: 12pt; color: #000000"><div><br></div><div><br></div><hr id="zwchr" data-marker="__DIVIDER__"><div data-marker="__HEADERS__"><blockquote 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;"><b>From: </b>"Remi Forax" <forax@univ-mlv.fr><br><b>To: </b>"David Alayachew" <davidalayachew@gmail.com><br><b>Cc: </b>"core-libs-dev" <core-libs-dev@openjdk.org><br><b>Sent: </b>Wednesday, January 10, 2024 8:19:15 AM<br><b>Subject: </b>Re: Gatherers -- conditionalWindowFixed?<br></blockquote></div><div data-marker="__QUOTED_TEXT__"><blockquote 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;" 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;"><div style="font-family: arial, helvetica, sans-serif; font-size: 12pt; color: #000000;" data-mce-style="font-family: arial, helvetica, sans-serif; font-size: 12pt; color: #000000;"><div>Hello David,<br></div><div>testing the gatherer api, I also wanted a "window" operation as the one you are describing.</div><br><div>My use cases is a text file with some sections containing items organized like this<br></div><br><div>:section1<br></div><div>item1<br></div><div>item2<br></div><div>item3<br></div><div>:section2<br></div><div>item1<br></div><div>item2<br></div><div>...<br></div><br><div>For me the signature of such method, windowGroupBy??, should take a Predicate (is a section, so the reverse of what you are suggesting) and a function that take a value (for which the predicate is true) and return a Collector,<br></div><div>so I can write something like<br></div><br><div> record Section(String name, List<String> items) {}<br></div><div> String input = ...</div><div> List<Section> sections = input.lines()<br></div><div> .gather(Gatherers.windowGroupBy(line -> line.startsWith(":"), name -> Collectors.<span class="element-name">collectingAndThen</span>(Collectors.toList(), list -> new Section(name.substring(1), list))))<br></div><div> .toList();<br></div></div></blockquote><div><br></div><div>Thinking a little more, having a function that returns a Collector is a kind of an anti-pattern, it would be better to decouple the function that creates the section and the collector, so the same collector is re-used.<br></div><div>So windowGroupBy?? should take a predicate, a collector and a function that takes the value (for which the predicate is true) and the result of the collector.<br data-mce-bogus="1"></div><div><br></div><div><div style="background-color: #ffffff; color: #080808;" data-mce-style="background-color: #ffffff; color: #080808;"><pre style="font-family: 'JetBrains Mono',monospace; font-size: 9.8pt;" data-mce-style="font-family: 'JetBrains Mono',monospace; font-size: 9.8pt;"><<span style="color: #007e8a;" data-mce-style="color: #007e8a;">T</span>, <span style="color: #007e8a;" data-mce-style="color: #007e8a;">R</span>, <span style="color: #007e8a;" data-mce-style="color: #007e8a;">R2</span>> <span style="color: #000000;" data-mce-style="color: #000000;">Gatherer</span><<span style="color: #007e8a;" data-mce-style="color: #007e8a;">T</span>, ?, <span style="color: #007e8a;" data-mce-style="color: #007e8a;">R2</span>> <span style="color: #00627a;" data-mce-style="color: #00627a;">windowGroupBy</span>(<span style="color: #000000;" data-mce-style="color: #000000;">Predicate</span><? <span style="color: #0033b3;" data-mce-style="color: #0033b3;">super </span><span style="color: #007e8a;" data-mce-style="color: #007e8a;">T</span>> <span style="color: #000000;" data-mce-style="color: #000000;">predicate</span>, <span style="color: #000000;" data-mce-style="color: #000000;">Collector</span><? super <span style="color: #007e8a;" data-mce-style="color: #007e8a;">T</span>, ?, ? extends <span style="color: #007e8a;" data-mce-style="color: #007e8a;">R</span>> <span style="color: #000000;" data-mce-style="color: #000000;">collector</span>, <span style="color: #000000;" data-mce-style="color: #000000;">BiFunction</span><? <span style="color: #0033b3;" data-mce-style="color: #0033b3;">super </span><span style="color: #007e8a;" data-mce-style="color: #007e8a;">T</span>, ? <span style="color: #0033b3;" data-mce-style="color: #0033b3;">super </span><span style="color: #007e8a;" data-mce-style="color: #007e8a;">R</span>, ? <span style="color: #0033b3;" data-mce-style="color: #0033b3;">extends </span><span style="color: #007e8a;" data-mce-style="color: #007e8a;">R2</span>> <span style="color: #000000;" data-mce-style="color: #000000;">mapper</span>)</pre></div></div><div><br data-mce-bogus="1"></div><div>Rémi<br data-mce-bogus="1"></div><div><br data-mce-bogus="1"></div><blockquote 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;" 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;"><div style="font-family: arial, helvetica, sans-serif; font-size: 12pt; color: #000000;" data-mce-style="font-family: arial, helvetica, sans-serif; font-size: 12pt; color: #000000;"><div><br></div><br><hr id="zwchr"><div><blockquote 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;" 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;"><b>From: </b>"David Alayachew" <davidalayachew@gmail.com><br><b>To: </b>"core-libs-dev" <core-libs-dev@openjdk.org><br><b>Sent: </b>Wednesday, January 10, 2024 7:19:26 AM<br><b>Subject: </b>Re: Gatherers -- conditionalWindowFixed?<br></blockquote></div><div><blockquote 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;" 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;"><div dir="ltr"><div class="gmail_default" style="font-family: monospace;" data-mce-style="font-family: monospace;">And this may also be better named as a split method instead of the long conditionalWindowFixed.<br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Wed, Jan 10, 2024 at 1:17 AM David Alayachew <<a href="mailto:davidalayachew@gmail.com" target="_blank" rel="noopener" data-mce-href="mailto:davidalayachew@gmail.com">davidalayachew@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left: 1px solid #cccccc; padding-left: 1ex;" data-mce-style="margin: 0px 0px 0px 0.8ex; border-left: 1px solid #cccccc; padding-left: 1ex;"><div dir="ltr"><div style="font-family: monospace;" class="gmail_default" data-mce-style="font-family: monospace;">Oh, I made a mistake. Let me try it again.</div><div style="font-family: monospace;" class="gmail_default" data-mce-style="font-family: monospace;"><br></div><div style="font-family: monospace;" class="gmail_default" data-mce-style="font-family: monospace;">If the predicate is true, add the element to the current list (create list prior if needed). Else if the predicate is false, send the list down to the stream, then add the element to a new list (the new current list, if you will).<br></div><br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Wed, Jan 10, 2024 at 1:05 AM David Alayachew <<a href="mailto:davidalayachew@gmail.com" target="_blank" rel="noopener" data-mce-href="mailto:davidalayachew@gmail.com">davidalayachew@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left: 1px solid #cccccc; padding-left: 1ex;" data-mce-style="margin: 0px 0px 0px 0.8ex; border-left: 1px solid #cccccc; padding-left: 1ex;"><div dir="ltr"><div style="font-family: monospace;" class="gmail_default" data-mce-style="font-family: monospace;">Hello Core Libs Dev Team,<br><br>I have been reading through JEP 461 (<a href="https://openjdk.org/jeps/461" target="_blank" rel="noopener" data-mce-href="https://openjdk.org/jeps/461">https://openjdk.org/jeps/461</a>) about Gatherers, and I'm really excited for what this will enable for us.<br><br>By far, the most important functionality that this API facilitates is the ability to create windows. Anytime I needed a window, I was basically forced to use a for loop. Now, the 2 most common window cases are being handed to us for free. It is very much appreciated.<br><br>Could we add one more method for a conditionalWindowFixed? We would need to pass in some Predicate<T>. If the predicate returns true, create a list (if it does not already exist) then add the element to it. If the predicate returns false while the list is empty, then just move along to the next. Else if the predicate returns false while the list is non empty, pass the list down into the stream. So, you end up with Stream<T> -----> Stream<List<T>>.<br><br>The reason I think this is worth adding is because it facilitates a really common use case. We may not want all windows to be the same size.<br><br>Is this something worth adding to the Gatherers API?<br><br>Thank you for your time and help!<br>David Alayachew<br></div></div></blockquote></div></blockquote></div></blockquote></div></div><br></blockquote></div></div></body></html>