Better Java Streams with Gatherers - Inside Java Newscast #57

Поділитися
Вставка
  • Опубліковано 4 чер 2024
  • Java's stream API needs more intermediate operations but instead of implementing some of them, Stream::gather, a new meta-operation, allows the JDK and us to implement all operations we need as Gatherers without overloading the `Stream` interface. Here's how to create Gatherers from an initializer, integrator, finisher, and combiner.
    ~~ Links ~~
    JEP 461: openjdk.org/jeps/461
    Implementing Gatherers: • Implementing New Java ...
    Code for your experimentation: github.com/nipafx/demo-java-x...
    VS Code extension: marketplace.visualstudio.com/...
    Announcement: inside.java/2023/10/18/announ...
    ~~ Chapters ~~
    0:00 Intro
    1:03 Gatherer - Terminology
    1:51 Gatherer - Integrator
    2:59 Gatherer - Initializer
    5:20 Gatherer - Finisher
    7:01 Gatherer - Combiner
    7:16 Gatherers
    8:07 Oracle VS Code Extension
    8:35 Outro
    Tags: #Java #OpenJDK #InsideJava
  • Наука та технологія

КОМЕНТАРІ • 24

  • @kinsleykajiva
    @kinsleykajiva 7 місяців тому +4

    Thank you for explaining this as well !

  • @thoriig3887
    @thoriig3887 7 місяців тому +6

    Looking forward for 461 since Viktor Klangs session about it at devoxx in belgium. making streams so much more versatile and flexible. glad that it gets more love now ❤ kudos to Viktor and you. a major gain for jdk development 🖖

    • @nipafx
      @nipafx 7 місяців тому +2

      Thank you! Positive feedback like this (for both the JEP and the video) is always appreciated. 😊

  • @tachyba
    @tachyba 7 місяців тому +6

    The idea seems very promising, can't wait for it!

  • @prdoyle
    @prdoyle 7 місяців тому +2

    This is big news! Thanks for sharing it!

  • @npexception
    @npexception 7 місяців тому +7

    I've been hoping for something like this to come to Java ever since I started enjoying the many variations of sequence manipulations in Clojure. Can't wait to finally get similar flexibility in Java! :)

    • @geraldodev
      @geraldodev 2 місяці тому

      @npexception do you use both at your current job, or just java ?

  • @matyas94k
    @matyas94k 7 місяців тому +6

    Well, we now need a JEP for Stream Hunters ('dunno, maybe something running on a daemon thread and yielding some specific elements when processing marked streams on the main thread), so we can declare that the Streams API evolved into a hunter-gatherer stage. :D

    • @nipafx
      @nipafx 7 місяців тому +2

      I'll forward this to Viktor (who's idea gatherers are) - let's see whether he can come up with something. 😂

  • @heinrich3427
    @heinrich3427 7 місяців тому +4

    Great addition to the API. It could basically replace all intermediate operations on a Stream. mapMulti, added in 16, already looks like legacy because it is a subset of what Gatherers will provide. A little bit unfortunated.

    • @nipafx
      @nipafx 7 місяців тому +2

      Good point on `mapMulti` - it really feels like a (weak) precursor to gatherers.

  • @sillystuff6247
    @sillystuff6247 7 місяців тому

    _appreciate_ the *null* background music 💙

  • @radoandrey2268
    @radoandrey2268 7 місяців тому

    Thank you

  • @derrickheng564
    @derrickheng564 7 місяців тому +1

    Keep up the good work Nick!

    • @nipafx
      @nipafx 7 місяців тому +1

      Thanks, I will. 😊

  • @USONOFAV
    @USONOFAV 7 місяців тому

    8:55 Where did the mapper come from?

    • @nipafx
      @nipafx 7 місяців тому

      You mean 2:55, right? The code I show here is somewhat incomplete, so it fits on screen. All gatherers I show would have to be built in and returned from a factory method that takes arguments like the `nrOfElements` for `limit` and `mapper` for `map`. You can see this hinted at in the comment above the snippet I show. To see the full code: github.com/nipafx/demo-java-x/blob/main/src/main/java/dev/nipafx/demo/java_next/api/gather/CustomGatherers.java#L90-L97

  • @Oprenova
    @Oprenova 7 місяців тому +1

    I don't understand it. Sounds like it does the same thing as filter

    • @31redorange08
      @31redorange08 7 місяців тому

      Do you know what a filter does?

    • @nipafx
      @nipafx 7 місяців тому +4

      A Gatherer can do all kinds of things. It's easy to implement a filter with it - see 2:26. But you can also implement a bunch of other behaviors. A lot are mentioned throughout the rest of the video. If you want to better understand how that works, check out the companion video on my channel (link in the video description).

    • @prdoyle
      @prdoyle 7 місяців тому +4

      Perhaps try implementing limit() using filter.

  • @dominicbue1404
    @dominicbue1404 6 місяців тому

    haha for that mistake the gatherer will FINISH YOU 😂

  • @zoladkow
    @zoladkow 7 місяців тому

    I dunno, thats definitely more lively than coffee sipping, but too much gesticulation makes it hard to follow. I don't think java needs to try this hard to be hip 🤷
    Also, would help a lot if it wasn't just one channel, because now we get a mix of different content delivery and presentation styles, while, in some cases, also covering same topics. Whoever would want to see it all, could still subscribe to them all.
    Got coffee fetish? - go see this distinguished gentleman showing how blissfully he can sip. Got ADHD? - go see a dude armwrestling for your attention.
    LTT got it right - it seems they have a channel for each taste of content 😁🙃

    • @nipafx
      @nipafx 7 місяців тому +1

      Ouch. I'm not trying anything, it's just who/how I am. 😢
      We've been considering having several channels for a while now but there are lots of considerations on both sides of that argument and I don't think we're gonna do it.