I've Waited YEARS For This JavaScript Feature...

Поделиться
HTML-код
  • Опубликовано: 4 фев 2025

Комментарии • 448

  • @ruaidhrilumsden
    @ruaidhrilumsden 2 года назад +225

    "Programmers don't love naming things, programmers love programming."
    Couldn't have said it better. As I was watching this I was thinking 'this is kinda like why Tailwind is great'. I suppose great minds think alike!

    • @nathanfranck5822
      @nathanfranck5822 2 года назад +2

      Typescript has really helped me not to worry about the names of things, since it's trivial later to do a 'rename' refactor on a name that no longer matches it's data or usage. I often start a type definition or variable declaration with 'let thinger = ...' so that I can fill in the variable first, use it, and then stare at my code and figure out what 'thinger' should be named now that it is filled in and used, it's funny that this works but it's super effective for me.

    • @CottidaeSEA
      @CottidaeSEA 2 года назад +1

      @@nathanfranck5822 I name stuff result more often than I'd like to admit. Though to be fair, it's a very good name for most scenarios. Since I tend to declare variables early, it also allows readers to know immediately what is going to be returned.

    • @jonnylukejs
      @jonnylukejs 2 года назад +1

      but do we "love" programming or do we love hating ourselves?

    • @CottidaeSEA
      @CottidaeSEA 2 года назад

      @@jonnylukejs I love calling people idiot, even if that idiot is me.

    • @alexg4927
      @alexg4927 2 года назад +2

      Id rather say programmers don't like to think about unnecessary stuff. I tried Tailwind and even though I don't have to think about naming, I have to make my way though long lines of utilitary classes. And that's really annoying. The same issue arises when U have to think how to put into Tailwind some stuff that I might easily do with Css or Scss
      And another problem is that utilitary classes become so difficult to read especially when there are more than 10-20 of them for one JSX tag. I have to re-read again and again until I find what I'm looking for

  • @aidantilgner
    @aidantilgner 2 года назад +288

    Ugh I guess I'm finally gonna have to learn what functional programming is

    • @xtinctspecies
      @xtinctspecies 2 года назад +9

      It’s the best thing to have happened to me

    • @FlorianWendelborn
      @FlorianWendelborn 2 года назад +26

      TL;DR: Everything is a function, use them

    • @1vers1onmain
      @1vers1onmain 2 года назад +4

      only ever used functional programming

    • @talgy2671
      @talgy2671 2 года назад +6

      Functional programming is all about not repeating the same block of code but using this block inside a function and using the function instead of that block of code.

    • @Brunoenribeiro
      @Brunoenribeiro 2 года назад +2

      Oh you are in for a treat

  • @geeksy2278
    @geeksy2278 Год назад +2

    Great! Used in Elixir which is a great language

  • @oath_2d
    @oath_2d 2 года назад +129

    I love how javascript is slowly more and more adopting fp patterns
    This proposal will definitely have massive effect on the way we write our javascript code and the DX gains will be amazing

    • @rumplstiltztinkerstein
      @rumplstiltztinkerstein 2 года назад +7

      To be honest, when I first heard of a new feature coming to javascript, my first thought was "Another feature to bloat this old language even further". But now that I see what it does I think it is a good thing.
      Javascript has been trying to be a lot of things for a long time. It is a language that is a little bit of everything, and it doesn't seem to be the best at anything. Its strength should be on the high level code. Turning into something closer to a functional programming could make more sense in the future. Similar to what Python does, where it has libraries compiled in C running in it's high level runtime with garbage collector.
      I think that Javascript as a functional programming language would be easier to understand and debug.

    • @chiragsingla.
      @chiragsingla. 2 года назад +2

      @Angel developer experience.

    • @RaducuGabriel
      @RaducuGabriel 2 года назад +1

      @@rumplstiltztinkerstein js used to be functional until es6 classes and the frameworks pulled it to OOP

    • @kebien6020
      @kebien6020 2 года назад +1

      JavaScript was actually designed to be a functional language and then it was shoehorned into looking a bit like Java (Mostly syntactically, but also with things like adding null where undefined was just fine).
      But FP things like first-class functions, anonymous function expressions, closures where there from the start. Also, at some point (2009 maybe?) we got the really nice array methods like map and reduce, keeping the momentum for FP in JS.

    • @v01d_r34l1ty
      @v01d_r34l1ty 2 года назад

      @@RaducuGabriel i'd argue that prototypes and objects arguably made it OOP before classes. Classes just made it more OO. Meanwhile, new additions like this make it more functional. While I don't really use JS anymore, it will remain in my heart as one of my favorite languages because it's the most innovative for developer experience. I mean, it evolved from being a simple browser scripting language as it was when I first used it (a.k.a. a complete joke language that everybody hated) to being used in backend systems for servers.

  • @mattburgess5697
    @mattburgess5697 2 года назад +14

    I really like the pipeline operators from Elixir. It makes code based on functions (regardless of strictly FP paradigm) much more intuitive and readable.

  • @jpbz412b
    @jpbz412b 2 года назад +1

    You can make your own pipe too:
    function pipe(...fns) {
    return function apply(arg) {
    return fns.reduce((prev, curr) => {
    return curr(prev)
    }, arg)
    }
    }
    And use it like this:
    pipe(
    toUpper,
    trim,
    removeNumbers,
    )(" test123")

  • @Darkitz69
    @Darkitz69 2 года назад +68

    Don't like the hyping up too much, but seeing proposals is really cool.
    Maybe you could do a video just digging trough a few proposals and explain the use-cases? (negative ones aswell, please)
    Or a video for each one.
    Seeing things move in javascript (and libraries) makes the ecosystem feel more alive and is great.

    • @CottidaeSEA
      @CottidaeSEA 2 года назад +5

      Disadvantages:
      Another peculiar operator you need to know.
      Awkward symbols, a pain for international keyboards.
      If logging needs to be done, the chain needs to be broken which means refactoring the entire function to keep the result the same if you do not wish to add logging in the implementations.
      Advantages:
      No need for reassigning values.
      Linear flow, makes it easier to read without the nesting.
      Possible performance gains depending on implementation.
      That's about all I can think of. I'd say better to have it than not, but I'm not too fond of it myself. I prefer the Visitor pattern in OOP, which is the equivalent of this. This is much faster to write out though, less structure necessary.

    • @TheChodex
      @TheChodex 2 года назад +5

      @@CottidaeSEA "Awkward symbols, a pain for international keyboards." - I don't agree with this, | and > are very common symbols for any programmer - you need | for "or" statement, and you need > when doing comparisons, so "pain for international keyboard" is invalid argument

    • @howdyimflowey4341
      @howdyimflowey4341 2 года назад +2

      @@TheChodex They are very common, but when typed separatedly.
      In spanish keyboards for example, the keys are located in completely opposite sides of the keyboard, and you need to use two different modifiers (shift for > and altgr for |).

    • @thefeymesaleng
      @thefeymesaleng 2 года назад

      @@howdyimflowey4341 man of culture 👏👏

    • @CottidaeSEA
      @CottidaeSEA 2 года назад

      @@TheChodex |>% all three are necessary and they all need some sort of Alt/Shift combination. While they are all used, you rarely use so many of them in succession. That's why they are awkward.

  • @xxmythmakerxx
    @xxmythmakerxx 2 года назад

    these sort of videos are rly cool and insightful, pls do them more often!!

  • @prakharmathur619
    @prakharmathur619 2 года назад

    yes please do make more videos like this. We need them!
    I saw your first video yesterday and immediately subscribed.
    We need more videos that relate to the real life scenarios that developers face, not just tutorials.
    great work man !

  • @eberechiuche799
    @eberechiuche799 2 года назад +1

    Hey Theo, love your videos a lot, always learning a bunch from you, as an entry level dev I could just watch your videos and see your approach to things and your rants and I can instantly know what not to do and what to do. Thanks a lot

  • @wownord
    @wownord 2 года назад +4

    I really like the equivalent in Clojure (called "threading macros" there).
    They have things like:
    thread-first (->) Inserts value of previous function as first parameter of next
    thread-last (->>) Same but as last param
    thread-as (as->) Give param a name, like %
    So it would be something like:
    (defn piped [x]
    (-> x
    add-two
    square
    square
    square))

  • @arturmuellerromanov4438
    @arturmuellerromanov4438 2 года назад +7

    I don't know if to love or hate this channel. Sometimes it's infuriating, sometimes enlightening. Guess that's properties of fire.

    • @dongueW
      @dongueW 2 года назад

      😂😂

    • @yestermonth
      @yestermonth 2 года назад

      Same opinion here, still the reason I haven't subscribed yet 💀

  • @atla5_
    @atla5_ 2 года назад +5

    Another FP feature I hope will land into JavaScript is pattern matching

  • @Codehood
    @Codehood 2 года назад

    Love this kind of videos. Please post more of them

  • @pranitrock
    @pranitrock 2 года назад +2

    I have used the single line approach before guess this is way more readable for later when you come back to that code.

  • @justfly1984
    @justfly1984 2 года назад +1

    You finally sold me a pipe operator. Waiting for somebody to sell me decorators.

    • @jon1867
      @jon1867 2 года назад

      I think it can be nice in OOP, which I hate OOP so I don't care haha

  • @andreicojea
    @andreicojea 2 года назад +37

    As someone who started web dev when most people were using Internet Explorer 6, I love how JS language and then ecosystem evolved over the past few years ❤

    • @daleryanaldover6545
      @daleryanaldover6545 2 года назад +3

      I started a year later after Explorer 7 came out. Glad things are getting better and better.

    • @vikingthedude
      @vikingthedude Год назад

      How do you feel about label statements?

  • @pedromenezes4013
    @pedromenezes4013 2 года назад

    yess! love to hear about stuff that's coming. I feel sharing it with more people is a good way to track its relevance

  • @LukePighetti
    @LukePighetti 2 года назад +2

    Love a pipe operator. Can be better than extension methods tbh

  • @joshuauzzell541
    @joshuauzzell541 2 года назад

    Thanks for hyping this up! Also, looking forward to this feature.

  • @nymusicman
    @nymusicman 2 года назад +1

    I do really like this kind of video. I'm really bad at staying up to date with new innovations and I can already think of several use cases in my apps this would be awesome for.
    And please release another video when it is implemented. Thanks!

  • @EdJones99
    @EdJones99 2 года назад +19

    Anything that takes away the need to come up with names is massive DX improvement imo. Really excited about this.

    • @m3hdim3hdi
      @m3hdim3hdi 2 года назад

      what DX mean?

    • @tendency5272
      @tendency5272 2 года назад +1

      ​@@m3hdim3hdi Developer experience

  • @xReDxTuRtLeZx
    @xReDxTuRtLeZx 2 года назад

    that seems super useful. looking forward to being able to use this in future apps

  • @diegodoumecq5144
    @diegodoumecq5144 2 года назад +2

    This is absolutely awesome. I've loved piping data through functions with stuff like lodash, it's sooo easy to grok but I've not been doing it as often as I'd like since lodash isn't exactly for everyone and it's massive. This is a game changer.
    Also Theo, yes to more videos like this. Newsy type of stuff is useful in its own way

  • @MarthinusBosman
    @MarthinusBosman 2 года назад

    I like these weird-newsy-thing-that-hasn't-happened-yet-but-you're-hyped-about-it videos

  • @AaronPrather
    @AaronPrather 2 года назад +1

    Isn’t this currently possible by writing a small pipe utility function that converts functions passed as args to an array, then using the reduce prototype method to call each one with the previous returned value?

  • @johnmcgg
    @johnmcgg 2 года назад

    excited for this! Yea, please do more videos like it :)

  • @scottiedoesno
    @scottiedoesno 2 года назад

    This is the quality comment I follow for. I probably wouldn't have known about this feature until months after its release without news-y stuff like this. Thanks a ton!

  • @2012ManCrazy
    @2012ManCrazy 2 года назад

    Awesome, always wanted pipe operator, now we just need to get some pattern matching

  • @fredericorinco9133
    @fredericorinco9133 2 года назад +2

    Pipes as type guards for typescript will be SO GOOD too. I can't wait for TS to support it after it's released xd

  • @xenossolitarius5478
    @xenossolitarius5478 2 года назад

    Oh dear lord, can't wait to blow my brains out seeing juniors pruducing 50 part pipes with this stuff.

  • @fueledbycoffee583
    @fueledbycoffee583 2 года назад +1

    LOVEIT functional array methods we're good but this is just godsend

  • @UliTroyo
    @UliTroyo 2 года назад

    This is great! Nushell made me a convert to pipes recently.

  • @codeChuck
    @codeChuck Год назад

    Good stuff! Firstly I though of this as a downgrade to readability. But after you said it will not perform assign operation, it sounds like it will be more performant. So the syntax becomes more bearable knowing it is ++ to perf :)

  • @JonLynchIsAlive
    @JonLynchIsAlive 2 года назад

    Ocaml has this as well. Javascript is my first love, so this would be awesome to see. Hope it makes it in!

  • @sanjarcode
    @sanjarcode 2 года назад

    Pipe sounds great.
    Array reduce can be used for piping, for now. let y = [addTwo, square].reduce((a, f) => f(a), x).
    Additionally, create a small wrapper to do this, called pipe. e.g. pipe(x, [addTwo, square]).
    The array can be spread over lines (Prettier default for long ones).

  • @aislanarislou
    @aislanarislou 2 года назад

    Finally!!!!
    That feature will be the key for apply Railway programming in Javascript easier and more cleaner than ever !!!!
    Excited for this coming before 2030 !!!!!

  • @Unc3
    @Unc3 2 года назад

    The idea is awesome.
    The syntax makes me cry.
    I really hope they reconsider the syntax.

  • @JFrameMan
    @JFrameMan 2 года назад +1

    I'm up for more of these videos. It's best to know ahead of time why something was made so you can make a judgment on whether to use it or not past the hype (or unpopularity) when it comes out.

  • @figloalds
    @figloalds 2 года назад

    2:19 "and we'll also be able to break this into a new line"
    Javascript return doesn't usually do that tho, I hope we will really be able to do that. It would be kinda hilarious if implicit statement termination remains the same as they implement this operator

  • @Loige
    @Loige 2 года назад

    Elixir fans will be ecstatic! Btw it might be interesting to do a deep dive and show how you could use the pipe with promises... fetch is the first example that comes to mind (step 1: make a request and get the response, step 2: extract the response body, step 3: process the body somehow).

  • @tomaszchmielnicki8676
    @tomaszchmielnicki8676 2 года назад

    The exception from the naming things issue seems to be nominal types

  • @aj35lightning
    @aj35lightning 2 года назад

    yes for more of these, i had no idea this was coming

  • @milesparker557
    @milesparker557 2 года назад

    Before I clicked on this video, I didn't know what piping was. Now I'm excited to get it!

  • @adriancaor
    @adriancaor 2 года назад +3

    Since I tested it in Elixir, I miss it in the other languages I have worked with. Good news for JavaScript!

  • @Lulu-wp4te
    @Lulu-wp4te 2 года назад

    Didn't know this was a thing this is awesome. I really hope it makes it too

  • @studiousllama4776
    @studiousllama4776 Год назад

    Oooh man this would be amazing. I hope this goes through.

  • @Spookyhoobster
    @Spookyhoobster 2 года назад

    They should change that "chalk.dim()" example. (I guess it might make more sense as a "use case" for a proposal rather than a basic "showcase" to get the idea across)
    My initial reaction was "Oh god, more obscure, hard to read syntax...", but your example with add/square made so much more sense. Lot cleaner than function calls inside function calls.

  • @voidmind
    @voidmind 2 года назад +1

    The operator has been a longtime coming. I thing it's been a TC39 proposal in some stage or another for many years.

  • @yapet
    @yapet 2 года назад +3

    It’s cool I guess, buuuuut. It seems that I am the only one worried about adding new syntax to js. It’s shiny and fancy, but it has a real impact on perf.
    The parsers are now required to be more complicated, and as such, parsing perf is impacted by it. Moreover, we are shipping oodles and oodles of JS, which cannot run until it is fully parsed. We have already experienced parsing perf decrease with the introduction of ES6 waaay long ago.
    It is cool to see JS being pushed forward. Just hope we won’t get another C++, with whole “design by committee” shenanigans attached. Maybe we would require some kind of depreciation strategy going forward. Maybe something akin to "use strict", that axed a part of the language (remember “with” statement anyone?)

    • @DryBones111
      @DryBones111 2 года назад

      This feature is easily transpiled, so if you want backwards compatability to older parsers, you can.

    • @yapet
      @yapet 2 года назад

      @@DryBones111 I'm referring to the future parsers perf (even on existing code, without the use of new features), not older ones compatibility. Of course you can transpile most of the new syntactic JS proposals.

  • @snailedlt
    @snailedlt 2 года назад

    Piping will be insane!
    It's one of the reasons why bash is so powerful with a very basic "standard library", and I can't wait for Javascript to get it!

  • @KeganVanSickle
    @KeganVanSickle 2 года назад

    This would be great to see in vanilla JS. Thanks for the update Theo!

  • @davidoriley
    @davidoriley 2 года назад +1

    In the meantime i've used the functional programming library "Ramda" which has a piping function to make piping a little less painfu. Its got some other pretty useful stuff too. But having piping adopted to native javascript would be *chefs kiss*

  • @christian-schubert
    @christian-schubert 2 года назад

    I usually put the to-be-executed functions on [an] argument[s] in an array and then piped that array through a reduce method - no need for intermediary variable naming

  • @jamesgl
    @jamesgl 2 года назад

    I love the newsy type of stuff keep it up

  • @somebody656
    @somebody656 2 года назад +1

    pipe in elixir is so good. I implemented something similar in Scala 3 using extensions

  • @barjo_
    @barjo_ 2 года назад

    I really hope for functions that have only 1 param you can purely pipe functions together like in Unix. Eg: return x |> addTwo |> square |> square |> square

  • @headlights-go-up
    @headlights-go-up 2 года назад

    100% enjoy these types of videos.

  • @Baraka0369
    @Baraka0369 2 года назад

    What I find really really cool in dart is the .. operator to chain function

  • @krazymeanie
    @krazymeanie 2 года назад +1

    Can't wait for this. I feel in love with pipe operators after using Elixir, this is gonna make Javascript hella fun to write

  • @ThugLifeModafocah
    @ThugLifeModafocah 2 года назад

    elixir pipe is amazing. One of the best ones, and for me, the best implementation of them all.

    • @jon1867
      @jon1867 2 года назад

      The pro I see to the hackpipe over elixir is that Elixir libraries always have a function signature of data first. With the hackpipes you don't have to convert functions to make them pipeable.

  • @andresmillsgallego814
    @andresmillsgallego814 2 года назад

    "programmers don't love naming things, programmers love programming"....amen! Nothing grinds my progress to a halt more than stopping to think of a name for something lol.

  • @AlecMaly
    @AlecMaly 2 года назад

    No way! One of the reasons I enjoy PowerShell scripting is the ability to pipe, similar to Bash scripting. It really lets you take advantage of the Unix mentality of single purpose programs/functions. Great content, I’ll be following this. I do hope they reduce it to a single character tho, the syntax is what makes it nice and feel so fluid.

  • @vikingthedude
    @vikingthedude 2 года назад +12

    I've been doing clojure for a few months and I love how we can seamlessly pipe many functions using the threading macros. This new feature will hopefully make things more readable in js. Kinda bummed that we have to call the func with % in every line of pipe, instead of just passing a function reference

    • @magne6049
      @magne6049 2 года назад +3

      % doesn’t call the func I think, but passes the result of the previous line explicitly. I think it’s much better than passing parameters implicitly.

    • @DjebbZ
      @DjebbZ 2 года назад +1

      It's better than Clojure, because with Clojure you have to choose where you pipe in the next function, either as the first or the last argument. Here with one syntax you get to pass it where you want.

    • @DryBones111
      @DryBones111 2 года назад +1

      Even better, allow piping of only arity-one functions, and supply a neat way to partially apply them without wrapping them in a new function. Then we can pipe function references AND reduce the ambiguity.

    • @magne6049
      @magne6049 2 года назад

      @@DryBones111 what is the best in class example of this? language and code?

    • @DryBones111
      @DryBones111 2 года назад +1

      @@magne6049 Haskell has a very terse syntax for this because all functions are curried by default. Because of this I'd say it's a prime example. However because Javascript doesn't curry functions by default you'd need a new syntax for currying.
      Haskell also doesn't have a pipe operator in the same way, instead there is an application operator `$` which applies the right hand side (evaluated) to the left hand side. Which works like a pipe but the code reads right to left.

  • @zenpool
    @zenpool 2 года назад

    yes! I've been using userland implementations of compose/pipe in JS for years! hopefully we'll get tc39/proposal-pattern-matching next,

  • @totalmonkeyspeed260
    @totalmonkeyspeed260 2 года назад

    Helpful video, educational on benefits of fp. Thanks 🙏

  • @dominuskelvin
    @dominuskelvin 2 года назад

    Interesting. Some functional programming goodies

  • @tomaszchmielnicki8676
    @tomaszchmielnicki8676 2 года назад

    Now all that we're missing is pattern matching, immutable data structures and tail call optimization

  • @i4o
    @i4o 2 года назад +1

    This is indeed a cool feature. Another feature I'm looking forward to using is the Temporal API (currently in stage 3), which solves issues with Date. Do check it out, if you haven't.

    • @robertholtz
      @robertholtz 2 года назад +1

      That’s great news. It’s absurd how cryptic vanilla JS is about handling time.

  • @jaredsmith5826
    @jaredsmith5826 2 года назад +2

    Interested to see how they end up handling Promises and async in pipes. "I learned it in Elixir" I'd be willing to bet you learned it in the shell years before :D

  • @TylerTriesTech
    @TylerTriesTech 2 года назад

    Bash was my first language that exposed me to piping. You can also do something similar in Python called "method chaining" but that only works with methods not functions.

  • @Kavukamari
    @Kavukamari 2 года назад

    oh, i like doing the same with array types in js, because they have member functions that process the whole array
    so I'd do like,
    val = array.
    filter([find a particular thing in the array]).
    map([get a single part of every item]).
    reduce([combine them into a single result value])
    return val
    or something like that, it looks like this is similar, but easier to use

  • @xTomster
    @xTomster 2 года назад

    I’m just here to post something to support the channel. Cool video of course.

  • @top_cope
    @top_cope 2 года назад

    fp-ts has such a nice pipe function. I've been using it for years

  • @pauloffborba
    @pauloffborba 2 года назад

    I'm using those pipes in Elixir lang and it's really awesome.

  • @mattbeaulne2516
    @mattbeaulne2516 2 года назад

    When I started using elixir I fell in love with it. I can't wait for this to be in JS

  • @asdougl
    @asdougl 2 года назад

    Love the concept, not too keen on the syntax but I’m sure I’d get used to it (and I can’t think of anything better)

  • @aldofiore2895
    @aldofiore2895 2 года назад +2

    I really hope they implement it in a way where I don't have to pass anything to the function, kinda of like `x |> addTwo |> square`. it seems a bit more readable to me then having a having a character as a the parameter, but might just be me.

    • @viniciusataidedealbuquerqu2837
      @viniciusataidedealbuquerqu2837 2 года назад

      it's impossible to do this way since there's no function currying in JS. and this really hinders partial application in which this is being used

    • @coomservative
      @coomservative 2 года назад

      big agree, or have it like lambda and you pick the carrier symbol, “x” being a common choice, that way you can use functions that take multiple arguments and you pass constants in or w/e
      // val is starting point, x then carries results, here we add two, then square it, then cube it
      return val.pipe(x
      |> addTwo(x)
      |> square(x)
      |> Math.pow(x, 3)
      );

    • @viniciusataidedealbuquerqu2837
      @viniciusataidedealbuquerqu2837 2 года назад +1

      they are using this from clojure anonymous fn but clojure still has point free application

    • @DryBones111
      @DryBones111 2 года назад +1

      @@viniciusataidedealbuquerqu2837 this is true, which is why this feature should be shipped with a clean syntax for partial application. Might as well double up that syntax for currying too.
      For the lack of better syntax:
      function(a, b, c) {...}
      To curry could be:
      functionA{}
      To partially apply:
      function{a, b}
      You can then pipe the arity-one function:
      c |> functionA{a, b}
      Or even better, if Typescript allowed us to curry all functions by default and we could just use the existing syntax:
      functionA(a, b) |> (c) === function(a, b, c)

  • @industry_std
    @industry_std 2 года назад +4

    I've always loved this feature without even knowing it existend! Glad to see it get closer to being a real thing. I wish the discourse online would show this kind of advancement in the language over other less useful/unnecessary ones such as the dreadful type annotation thing.

  • @brielov
    @brielov 2 года назад

    I've been waiting for this (and pattern matching) for a very long time now. With those two I'd be a lot happier with the language.

  • @limitlesskode
    @limitlesskode 2 года назад

    I’ve used this in Elixir. I’m excited it’s coming to JS🎉

  • @RoiTrigerman
    @RoiTrigerman 2 года назад

    that's why I love rxjs so much

  • @Epic0n
    @Epic0n 2 года назад

    I've been waiting for a pipeline operator in js for tha last five years, and eventually, it got to stage two. It's cool ))

  • @obesebilbo5824
    @obesebilbo5824 2 года назад

    Use the lodash ‘flow’ function. You probably already have it as a dependency in your project anyway.

  • @EugenioCarmo
    @EugenioCarmo 2 года назад

    Please make more videos like this one 👏🏻😀

  • @taureon_
    @taureon_ 2 года назад

    i think this may be a bit confusing because the return statement has stuff running after it, so if it gets added i would put it all in a temp variable and return that

    • @yapet
      @yapet 2 года назад

      We already have method chaining, which looks exactly the same, yet I don’t think it’s a concern when writing returns.
      Same goes for jsx, I feel like. There is a lot of code run, before return is evaluated.
      I don’t feel like this needs to be accounted separately for.

    • @taureon_
      @taureon_ 2 года назад

      @@yapet i forgot about method chaining because i dont use methods a lot, my bad

  • @ukaszzbrozek6470
    @ukaszzbrozek6470 2 года назад

    There are libraries that implement pipe for example Rambda. I didn’t hear about it very popular. I would be sceptical.

  • @loumadev
    @loumadev 2 года назад

    1:41 `^` is a bitwise XOR operator. Exponentiation operator is `**`.

  • @jetseverschuren
    @jetseverschuren 2 года назад

    It almost feels like a 1:1 copy from Elixir. It's one of the features I enjoyed most

  • @kamilzielinski1303
    @kamilzielinski1303 2 года назад

    i hope that % will be and it will automatically pass the returned value as first argument

  • @tlgr3g
    @tlgr3g 2 года назад

    My most awaited feature (maybe together w/ Temporal). Hope it gets on the TypeScript roadmap as soon as they settle on the token for the topic reference. They could very simply compile it away into nested calls anyway. Right now, typing a pipe function is a huge pain in TS. Though that would probably be solved with partial generics inference too, which is on the roadmap after 5.0.

  • @yapet
    @yapet 2 года назад +2

    I’m kinda excited how this may impact library design. We all love method chaining for exactly the same reasons pipe operator is a thing. Right now you are required to put methods on an object / prototype to achieve that.
    Modern bundlers (generally*) don’t strip out object properties, since they cannot guarantee, that you won’t `Object.keys` them (or something similar).
    We might see a trend in libraries that expose just functions as opposed to methods on an object and expect you to use pipe to get ergonomics of method chaining. That way bundlers can tree-shake unused functionality more aggressively.
    *Compilers like Google Closure, can analyze through things like that. Kinda sad that almost nobody seems to use it (unless you are a Clojure JS developer). I feel like making JS compilers more accessible can be a HUGE positive change for the community.

  • @PauloPM8000
    @PauloPM8000 2 года назад

    This is the best type of video imo

  • @avi12
    @avi12 2 года назад +6

    While the pipe operator seems very cool and useful, you should be very careful with it
    1. If you have too many pipes and one of them has a bug, good luck debugging, especially if they're one-liners
    2. It makes it far less readable
    I'm a "const" kind of guy, i.e. I'd rather name everything to make the code readable than use "let" and reassign variables, making the code far less predictable

    • @OryginTech
      @OryginTech 2 года назад

      You missed the plot here entirely

    • @whatplan4335
      @whatplan4335 2 года назад

      For 2, the thing is most of the time this is unnecessary and requires a lot of thought to name it something appropriate, where pipes allow you to just clearly show the flow of data from function of function. If you want to add a name, it’s very easy to add in an in line comment.

    • @ocwebdesigndev54
      @ocwebdesigndev54 2 года назад

      1. For implicit bugs, can easily add pipes in between pipes for logging the value tranformations. For explicit ones the stack trace can easily have "error at doSomething pipe#3". Or if not, then you still have at-line or at-function error logging and it shouldn't be too different
      2. With one-off anonymous pipes I see your point. However at scale it should force creating smaller functions to make the piping readable which would improve readability and DRY throughout a codebase.
      Overall, people who write bad code will write bad functional code. There are tradeoffs but piping does make some situations more readable

    • @DryBones111
      @DryBones111 2 года назад

      Bugs aren't so much of an issue if you embrace functional composition, making use of strong static typing, and keeping the code declarative. And the few that sneak through will be caught in your tests, which are now extremely simple to write.
      Also, pipes are equivalent to using const at each stage. Nobody will be mutating those values before they're passed on to the next function.

  • @joshsanderlin2979
    @joshsanderlin2979 2 года назад

    This sounds amazing! I love FP and really hope this gets added to JS.

  • @p0tofpie
    @p0tofpie 2 года назад

    This is a dope video do more

  • @TheChodex
    @TheChodex 2 года назад

    At first I was like "hmm I don't know"", but then you won me over with the 3:29 because I got flashbacks from the React when I want to wrap component with few hocs then it's like `withSomething(withSomethingElse(withAnotherSomething(MyComponent, anotherExtraStuff), somethingElseExtraStuff), somethingExtraStuff)` which is annoying to read, this pipe operator is gonna make it much more understandable

  • @harrytsang1501
    @harrytsang1501 2 года назад

    When I first learned pipe in bash, I didn’t even think of it as a variable.
    I just want the value passed to the next thing

  • @thomassynths
    @thomassynths Год назад

    This is rather nice. Would be cool if Haskell had that syntax sugar (without resorting to quasi-quotation).

  • @MarkJaquith
    @MarkJaquith 2 года назад

    Yes, do more of these.