Gatherers -- windowBy
David Alayachew
davidalayachew at gmail.com
Sun Aug 4 07:22:05 UTC 2024
Just realized that 4 and 5 will become dead links after my next commit. So
here is a link tied to the commit.
https://github.com/davidalayachew/HowFastCanYouType/blob/e3ed9880a0927e84ebf8e5858cdcca9581186034/src/main/java/HowFastCanYouTypeModule/HowFastCanYouTypePackage/GUI.java#L151
On Sun, Aug 4, 2024 at 3:14 AM David Alayachew <davidalayachew at gmail.com>
wrote:
> Hello Core Libs Dev Team,
>
> Apologies for the massive delay. I have been juggling many severe personal
> emergencies, and thus, did not have time or strength to follow up on the
> previous thread --
> https://mail.openjdk.org/pipermail/core-libs-dev/2024-January/117718.html
>
> As mentioned in my previous thread, I have been extremely happy with the
> new Gatherers API, and have found numerous uses for it.
>
> I did want to add one addition to the list of premade gatherers provided
> by the standard library in java.util.stream.Gatherers API -- a windowBy
> gatherer.
>
> The result of the thread was that, while the feature had nothing wrong
> with it, evidence needed to be provided of its utility. This email is that
> evidence. Specifically, this email is providing all of the situations where
> I used this windowBy Gatherer that Viktor Klang made for me, with the hope
> that it is strong enough evidence to push this method into the Gatherers
> API.
>
> Here we go.
>
> 1. Advent of Code 2020 -- Day 14 [1] -- and here is my code [2] --
> here is a link to the line that actually used the gatherer [3]
> 1. This cleaned up my solution CONSIDERABLY. If I was doing this with
> for loops, I would have to do index manipulation to jump ahead my for loop
> index wise. Here, all I am doing is telling it how to split apart the
> stream. Way more clear and elegant. Which was critical because this AOC day
> was extremely difficult for me. Solution is not yet done, but making great
> progress.
> 2. Service Health Analytics -- Work project, so I can't share the
> code
> 1. This was a super basic use case, but long story short, I'm
> tracing down yet another network issue, and I wanted to know what was
> occurring before the network outage, to see if there was a correlation. I
> ended up scrapping this solution in favor of another one, but I was quite
> happy with how easy the Gatherer made it to grab exactly what I wanted. It
> was just a windowBy followed by a sliding window, and then extracting some
> info by comparing the 2 chunks.
> 3. Typing Metrics [4] -- here is the link to the method that uses
> the Gatherer [5]
> 1. This is where I really put the Gatherer through its paces. I had
> some semi-complex examples, but I got them all to work out well. It made my
> logic simpler than the imperative equivalent, while also keeping things
> concise. Now, one point that caused me some difficulty was recognizing that
> the Gatherer has a surprisingly large number of edge cases. For example,
> when looking at the data in aggregate, you notice a pattern -- the first
> element of every window is the FALSE case of your predicate, while all
> remaining members of that window are the TRUE case of the predicate.
> However, it's very possible for the first window to be a single element
> TRUE case window. I think this is the first time I found a valid use for
> the Stream::dropWhile method lol. But otherwise, this feature REALLY helped
> me move forward, and I am very happy with it!
>
> My biggest takeaway from using this Gatherer is that, when dealing with a
> Stream of events that you want to get metrics of, this gatherer is going to
> be a critical tool in the arsenal. This Gatherer also pairs BEAUTIFULLY
> with slidingWindow, to where I feel it made sliding window even stronger. I
> break up my stream into chunks using the windowBy, then slide over those
> chunks using sliding window. I kept finding myself using this strategy to
> aggregate and analyze. To use an analogy, it feels almost like making a
> database view of a larger database table.
>
> This is my experience using the windowBy Gatherer that Viktor Klang gave
> me. Please let me know if there are any questions, comments, or concerns.
>
> Thank you for your time, patience, and understanding!
> David Alayachew
>
> [1] = https://adventofcode.com/2020/day/14
> [2] =
> https://github.com/davidalayachew/Advent_of_Code/blob/1f054282d610af444dd27be4dfb374e10ac76db4/AOC/AOC_2020.java#L334
> [3] =
> https://github.com/davidalayachew/Advent_of_Code/blob/1f054282d610af444dd27be4dfb374e10ac76db4/AOC/AOC_2020.java#L468
> [4] = https://github.com/davidalayachew/HowFastCanYouType
> [5] =
> https://github.com/davidalayachew/HowFastCanYouType/blob/main/src/main/java/HowFastCanYouTypeModule/HowFastCanYouTypePackage/GUI.java#L151
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/core-libs-dev/attachments/20240804/43e52dbb/attachment.htm>
More information about the core-libs-dev
mailing list