Teaching old Streams new tricks By Viktor Klang

  Рет қаралды 22,629

Devoxx

Devoxx

Күн бұрын

Пікірлер: 40
@dazraf
@dazraf 9 ай бұрын
Love Viktor's presentation style and content. Learnt loads from this presentation. It's great news to see so much progress in the JDK!
@viktor_klang
@viktor_klang 9 ай бұрын
I really appreciate that, @dazraf-thank you!
@admendoz25
@admendoz25 Жыл бұрын
I am only 12 minutes into this presentation and I've learned a lot. Great work Viktor
@viktor_klang
@viktor_klang Жыл бұрын
Thank you so much!
@b_two
@b_two Жыл бұрын
Love the inclusion of an andThen api!
@SwarangaSarma
@SwarangaSarma Жыл бұрын
Amazing work! Showed me operations that I didn't even think I needed but I do now.
@viktor_klang
@viktor_klang Жыл бұрын
That's awesome to hear!
@TheodoreRavindranath
@TheodoreRavindranath Жыл бұрын
Amazing work. Looks a lot inspired by Reactive frameworks. But, this is much simpler and sounds like this would be a great addition to Java.
@lfeng0766
@lfeng0766 Жыл бұрын
Amazing presentation.
@viktor_klang
@viktor_klang Жыл бұрын
Thank you!
@hepin1989
@hepin1989 10 ай бұрын
Nice and detail explain
@viktor_klang
@viktor_klang 9 ай бұрын
Thank you, @hepin1989!
@Muescha
@Muescha Жыл бұрын
I expected the Gatherers to include all the methods from the java-util-stream-Stream as well (perhaps in a different class like `DefaultGatherers` or `CoreGatherers`). This way, I could also use these methods to create connecting Gatherers with the `.andThen` function.
@Justjames283
@Justjames283 Жыл бұрын
Great presentation!
@viktor_klang
@viktor_klang Жыл бұрын
Thank you! :)
@Jankoekepannekoek
@Jankoekepannekoek Жыл бұрын
I hope this will come as an incubator api soon.
@bizoitz86
@bizoitz86 Жыл бұрын
Will Collectors do something about short#-circuiting as well, or will we have to short circuit in gatherers and then reduce? I.e. implementing allMatch.
@viktor_klang
@viktor_klang Жыл бұрын
I personally don't think that's possible to do as the evaluation strategy for Collector is already established and no current evaluation implementation checks for short-circuting. As such, I suspect that it would be hard to implement it in a backwards-compatible way.
@IgnacioVaras-o3n
@IgnacioVaras-o3n Жыл бұрын
Cool stuff, is there any way to play with it, other that implementing it myself?
@iplantevin
@iplantevin 4 ай бұрын
I hope this will make its way beyond previews, to catch up to, and to some extent, improve on Kotlin's more powerful collection API 🤞
@avalagum7957
@avalagum7957 Жыл бұрын
When will we have these things in Java to play with? If Viktor Klang talks about this, I'd like to see the comparison with Scala.
@viktor_klang
@viktor_klang Жыл бұрын
Follow the progress of JEP-461: Stream Gatherers for more info
@DesuTechHub
@DesuTechHub Жыл бұрын
I see this gather is somewhat similar to spark functions data frame api's expr functions. Happy that, we are taking good things...
@Sakrosankt-Bierstube
@Sakrosankt-Bierstube 8 ай бұрын
5:10 Ngl, i am a little bit conused.. reorder() exists as sort(), duplicateConsecutive() exists with distinct(), groupdUsing() exists through collect() and of course mapConcurrent() exists trhough map(). Yes.. you have to do some extra stuff instead of just putting a your lambda operation as argument but... it exists. All of that would be just another method name or syntax.
@viktor_klang
@viktor_klang 7 ай бұрын
My thinking is that reorder() can emit elements as they are determined to be next in order (using sequence numbers or otherwise), whereas sort can only start to emit once the entire upstream has been consumed-this will never terminate for unbounded streams. deduplicateConsecutive() is definitely not the same as distinct() as you only want to eliminate adjacent duplicates, and collect() is a terminal operation and not an intermediate one. And, unfortunately, mapConcurrent() cannot be implemented using map() since you need to flush during finish, and the contract of map() is also that the supplied function is stateless and non-interfering. I hope that helps :)
@DidierLoiseau
@DidierLoiseau 7 ай бұрын
I was kind of expecting at the end: “… and this is why we have decided to deprecate all intermediate operations in the Stream API in Java 23” 😅
@viktor_klang
@viktor_klang 7 ай бұрын
😂
@DidierLoiseau
@DidierLoiseau 7 ай бұрын
​@@viktor_klang Didn’t expect you to notice my comment! Since you are here, for the mapMulti() example at 26:07, shouldn’t the lambda return !downstream.isRejecting()? Also, I’m curious about isRejecting(), wouldn’t most usecases negate the returned boolean? Might be better to have isAccepting() instead - it would be more consistent with push().
@viktor_klang
@viktor_klang 6 ай бұрын
⁠@@DidierLoiseauSorry, completely missed your reply. Having mapMulti return !downstream.isRejecting() wouldn’t hurt, but on the other hand it doesn’t really fix the problem that the user-supplied BiConsumer cannot know when it must stop pushing. As for isRejecting instead of isAccepting is that we do not know if it is accepting, we only know if it is rejecting. isRejecting() is primarily intended to be used when the upstream wants to avoid performing expensive work which cannot be passed downstream anyway. For instance in the finisher.
@quickruss05
@quickruss05 Жыл бұрын
Love this as I've run into many cases where I've wanted to extend the streams API. I even ended up building something allowing arbitrary operators based on mapMulti since it was the first official operator to provide access to the downstream sink but it had many shortcomings and didnt parallelize, etc. I kept expecting him to point to the library that has this but then disappointed this is not available yet 😢. Looking forward to this. Some feedback though... gather and gatherer don't seem like the right names, why not operate and operator? Also, where does this fit with reactive streams API? Java streams are great but I've found gaps like it being pull-based (and not push-pull with backpressure like reactive streams) and doesn't inherently support asynchronous operations that have made me use reactive streams APIs instead. It would be good to incorporate these concepts into Java streams. That with virtual threads would truly kill reactive streams.
@viktor_klang
@viktor_klang Жыл бұрын
Java Streams are push-based (in general) over a Spliterator. As for naming it is always a challenge-as you can imagine, a lot of different names have been suggested (would be a long conversation to fully elaborate all the concerns to address). What gather+gatherer had going for it is its relationship with collect+collector :)
@USONOFAV
@USONOFAV Жыл бұрын
So... Gatherer is in Java 21 yet?
@viktor_klang
@viktor_klang Жыл бұрын
No, it is not in Java 21
@zaccicala2341
@zaccicala2341 Жыл бұрын
Maybe preview in 22
@DidierLoiseau
@DidierLoiseau 7 ай бұрын
@@zaccicala2341 indeed it is!
Жыл бұрын
Looks like most of this featurers Reactor already supports
@Muescha
@Muescha Жыл бұрын
I would anticipate having both `Gatherer::endThen` and an alias `Gatherer::gather = Gatherer::endThen`. Why, you ask? This would enable me to effortlessly extract a group of Gatherers from an existing Stream pipeline. Otherwise, I would have to go through the process of renaming them step by step, changing from `.gather()` to `.endThen`, while retaining the same functionality.
@viktor_klang
@viktor_klang Жыл бұрын
I decided against doing so because I found that it made code reviews more difficult to understand (am I looking at Stream composition or Gatherer composition here?). Reusing the name for composition used by things like Function made more sense to me.
Java 21 By Brian Goetz
48:25
Devoxx
Рет қаралды 23 М.
Serialization: A New Hope by Viktor Klang, Brian Goetz
50:53
Cheerleader Transformation That Left Everyone Speechless! #shorts
00:27
Fabiosa Best Lifehacks
Рет қаралды 16 МЛН
Tuna 🍣 ​⁠@patrickzeinali ​⁠@ChefRush
00:48
albert_cancook
Рет қаралды 148 МЛН
Support each other🤝
00:31
ISSEI / いっせい
Рет қаралды 81 МЛН
Better Java Streams with Gatherers - JEP Cafe #23
1:13:32
Design Patterns Revisited in Modern Java by Venkat Subramaniam
51:30
What's Looming in Spring? by VENKAT SUBRAMANIAM & JOSH LONG
52:26
Reactive Programming in Java by Venkat Subramaniam
52:20
Devoxx
Рет қаралды 122 М.
Project Leyden By Brian Goetz
54:39
Devoxx
Рет қаралды 8 М.
Cheerleader Transformation That Left Everyone Speechless! #shorts
00:27
Fabiosa Best Lifehacks
Рет қаралды 16 МЛН