How to Curry Functions | An Advanced Javascript Tutorial on Currying

แชร์
ฝัง
  • เผยแพร่เมื่อ 22 ก.ค. 2024
  • Web Dev Roadmap for Beginners (Free!): bit.ly/DaveGrayWebDevRoadmap
    Learn how to curry functions in Javascript. In this advanced javascript tutorial on currying, we will discover what a curried function is, how to curry functions, how to partially apply functions, and how to write a curry function.
    🚩 Subscribe ➜ bit.ly/3nGHmNn
    🚀 JavaScript for Beginners: Full Course (8 hours): • JavaScript Full Course...
    🔗 Advanced Javascript Concepts playlist:
    • Advanced Javascript Co...
    How to Curry Functions | An Advanced Javascript Tutorial on Currying
    (00:00) Intro
    (0:20) What is currying?
    (0:53) A basic example of currying
    (3:48) Partially applying curried functions
    (7:39) Function Composition with curried functions
    (12:53) Convert "normal" functions to curried functions with a curry function
    📚 References:
    "The Simplest Intro to Currying in Javascript":
    javascript.plainenglish.io/th...
    "What Is Currying in Javascript and Why Does It Matter?":
    / what-is-currying-in-ja...
    ✅ Follow Me:
    Twitter: / yesdavidgray
    LinkedIn: / davidagray
    Blog: yesdavidgray.com
    Reddit: / daveoneleven
    Was this tutorial about Currying Functions in Javascript helpful? If so, please share. Let me know your thoughts in the comments.
    #currying #functions #javascript
  • วิทยาศาสตร์และเทคโนโลยี

ความคิดเห็น • 173

  • @DaveGrayTeachesCode
    @DaveGrayTeachesCode  3 ปีที่แล้ว +10

    Currying functions in Javascript is an advanced topic. Once you understand how to curry a function and how to use curried functions, it can be a very useful feature in your code. This tutorial will cover the what, why, and how to's of currying functions in Javascript. All this talk of currying really just makes me hungry! 😂 If you are just learning Javascript, you should start with my full 8 hour course tutorial here: th-cam.com/video/EfAl9bwzVZk/w-d-xo.html

  • @hosamgnaba3205
    @hosamgnaba3205 ปีที่แล้ว +8

    Man, thank you for all these great tutorials , you hardly ever see some advanced topics like this on youtube, I really appreciate your efforts

  • @ironsand
    @ironsand 5 หลายเดือนก่อน

    Man, your video came to me in the exact time! I see for some days trying to understand a debounce function, and was about to ask in SO, but your video made me understand it. REALLY thanks.

  • @matinsasan
    @matinsasan 2 ปีที่แล้ว +17

    Please make more videos about advanced topics and concepts in an easy, digestible way you do naturally. TH-cam is filled with too many videos about basic stuff. You'll make a huge difference daring to be different from other youtubers. I enjoyed your explanations so much. Thanks.

    • @DaveGrayTeachesCode
      @DaveGrayTeachesCode  2 ปีที่แล้ว +2

      Thank you, Matin! 🙏

    • @dopetag
      @dopetag ปีที่แล้ว +1

      So true! It's like the holy grail of the js youtube here!

  • @tizahn5262
    @tizahn5262 ปีที่แล้ว +1

    I first learnt about the term 'curry' through a Leetcode Javascript qns. Even though curry function is a kind of higher order function, it is still quite hard for me to understand currying through a challenging question. Thanks so much for breaking down the concept of currying starting from a very simple example. I understand it a lot better now!

  • @CodeGoblin
    @CodeGoblin 2 ปีที่แล้ว +15

    I love that timeTen example, I've used currying before but other than to scope variables I didn't see much of a use case for it. The times 10 example really gives me a great reason for caring about it much more as it allows for possible cleaner reusable code. Great video Dave.

  • @shiboai8496
    @shiboai8496 6 หลายเดือนก่อน +1

    Thank you so much! really helped me to understand the Haskell function types

  • @CJ-nz5rt
    @CJ-nz5rt 3 ปีที่แล้ว

    beginner-friendly with easy to comprehend description. you're a genius!

  • @chunli680
    @chunli680 2 ปีที่แล้ว +8

    Thank you for making the content! I was confused by most of the JavaScript curry related contents, but this one really helped me understand well!

  • @neutechnica
    @neutechnica 6 หลายเดือนก่อน

    Thank you for this video. My head has been hurting all day trying to truly understand currying. I don't want to move on before I get the logic behind it. I'm not a 100% but I definitely felt some flashes of understanding while watching your video.

  • @ghosteng
    @ghosteng 3 ปีที่แล้ว

    My search ended here on complete understanding and the entire existence of curry functions.
    Very well explained. Thanks for the video!!

  • @xx_kyon
    @xx_kyon 7 หลายเดือนก่อน

    What a great class! thank you for teaching us with real-world usages of these concepts.

  • @BlaBlaBlaInDaHouse
    @BlaBlaBlaInDaHouse 5 หลายเดือนก่อน

    That's some great examples. Thank you for your explanation!

  • @AkshayKumar-kz6zh
    @AkshayKumar-kz6zh 2 ปีที่แล้ว

    Currying is such an important concept but the only video I could find a generalized currying function implementation is yours. Thank you !

  • @clintona1855
    @clintona1855 ปีที่แล้ว

    Man, this is really interesting. With the basic examples, it's like wtf for? But then you see it in action and... wow.

  • @justinnl4332
    @justinnl4332 2 ปีที่แล้ว +1

    Hey Dave, thanks for your advanced javascript concepts course. You lay down them pretty easily. All of these examples do help a lot, thank you very much!)

  • @elik3765
    @elik3765 ปีที่แล้ว

    Dave, thank you very much for all your efforts! I watch your videos over and oveer and every time a new layer of konwledges reveals itself and make me go "WOW!"

  • @stephen1569
    @stephen1569 ปีที่แล้ว

    Loving your content & delivery Dave!! Pure gold. Keep up the great work.

  • @fares.abuali
    @fares.abuali ปีที่แล้ว

    Thank you so much!
    Enlightening and much informative

  • @CODEABC
    @CODEABC 3 ปีที่แล้ว +7

    You are awesome..you teach us more easyly and briefly..hope you make more advanced topic

  • @MouwaficBadarou
    @MouwaficBadarou 2 หลายเดือนก่อน

    Crystal clear, amazing, thanks !

  • @davidmomoh7019
    @davidmomoh7019 2 ปีที่แล้ว

    Hi Dave, thank you very much. I wished I had found your channel sooner. I have had difficulty understanding this concept and I'm not even a beginner n JavaScript. Thank you very much. I've subscribed and gave the video a big like. I'm hoping to see more exciting and insightful videos.

  • @lynnenux5763
    @lynnenux5763 ปีที่แล้ว

    I REALLY liked this! Very clear. Thank you so much Dave. I'm off to make curry and recursively walk backwards through my tree data. I may be some time.

  • @marti9442
    @marti9442 ปีที่แล้ว +3

    It’s hard for me to understand some concepts. But i understood all of what you had to say about currying. Now i understand currying better than other topics that are alot simpler. Thanks

  • @l_t_m_f
    @l_t_m_f ปีที่แล้ว

    Love the advanced content! Explained very succinctly

  • @Xylasider
    @Xylasider 3 ปีที่แล้ว

    I recently started reading O'Reily Books' Learning React. They touch on currying for like a paragraph. This video opens up such a better understanding!

  • @kevinbegin3049
    @kevinbegin3049 2 ปีที่แล้ว

    Thanks for this video. I've watched a few and this did the best job of explaining why this is so useful.

  • @vincenzocristiano135
    @vincenzocristiano135 ปีที่แล้ว

    thanks a lot! great explanation! Cheers

  • @siavoshoon
    @siavoshoon ปีที่แล้ว

    I love all your videos, but it was best of all. Truly exciting. Thank you ⭐⭐⭐⭐⭐

  • @jadervinicius8634
    @jadervinicius8634 ปีที่แล้ว

    Wonderful explanation about the concepts of currying, now this concept is totally clear to me, thank you very much @Dave, please keep creating nice videos.

  • @MusicandCoding
    @MusicandCoding 2 ปีที่แล้ว

    This is awesome! Clear and to the point explanation.. Thank you! :)

  • @bobkazamakis5169
    @bobkazamakis5169 3 ปีที่แล้ว

    Great video, looking forward to more JS content as I'm a big fan of functional programming. Btw nice t-shirt 😁

  • @yuvrajgupta5144
    @yuvrajgupta5144 ปีที่แล้ว +4

    Damn dude, I just love the way you teach things. And the knowledge you are giving out to people is just marvellous. A person learns this kind of stuff while working in the industry. Thanks to you for teaching us beginners how things really work.

    • @DaveGrayTeachesCode
      @DaveGrayTeachesCode  ปีที่แล้ว +1

      You're welcome and thank you for the kind words!

    • @yuvrajgupta5144
      @yuvrajgupta5144 ปีที่แล้ว

      @@DaveGrayTeachesCode Quick question, do you have any plans for teaching us about Rest Apis in the upcoming videos?

  • @7rgdev
    @7rgdev ปีที่แล้ว +1

    Hey Dave ! Take a look at this problem :
    We need to write a curried sum finction which can accept any "n" numbers of params and at the end returns the sum of all the params. The catch is that in the end it will receive undefined as a parameter so that it knows to return the sum now :
    - sum(1)(2)(3)(); // should return 6
    sum(1)(2)(); // should return 3
    sum(1)(1)(1)(1)(1)(1)(1)(1)(1)(1)(1)(1)(1)(1)(1)(1)(1)(1)(1)(1)(1)() // you get the idea.
    How can we write something like this ??
    Thanks in advance !

  • @tedndg
    @tedndg 3 ปีที่แล้ว

    Never disappoints ,amazing job Dave

  • @yuliusseraph4973
    @yuliusseraph4973 2 ปีที่แล้ว

    Really great video. I return to it for the second time aldready.

    • @DaveGrayTeachesCode
      @DaveGrayTeachesCode  2 ปีที่แล้ว +1

      Thank you for the kind words, Yulius! 🙏

    • @yuliusseraph4973
      @yuliusseraph4973 2 ปีที่แล้ว

      @@DaveGrayTeachesCode especially for the currying function. I sometimes use it in my projects.

  • @ismailelsayed936
    @ismailelsayed936 2 ปีที่แล้ว +1

    man i don't know where you come from, you saved millions of wasting time

  • @rdrglpzcnt
    @rdrglpzcnt 2 ปีที่แล้ว

    thanks for the video!

  • @raptoress6131
    @raptoress6131 2 ปีที่แล้ว

    Thanks very much, my curry turned out delicious

  • @Gruby7C1h
    @Gruby7C1h 2 ปีที่แล้ว +4

    I think the key to understanding the curry function in this video is the part that uses bind: it creates a function that has part of the arguments "pre delivered".
    Simple example: the 5 will be automatically put to the add function (add5 is "fixed' with 5):
    const add = (x, y) => x + y;
    const add5 = add.bind(null, 5);
    console.log(add5(10)); // 15
    Hope it helps someone, who like me, has rather imperative background and FP concepts are puzzling.

  • @dharmeshgohil9375
    @dharmeshgohil9375 2 หลายเดือนก่อน +1

    hey dev what is use of null in this line return curried.bind(null, ...args)

  • @MostafaDev659
    @MostafaDev659 8 หลายเดือนก่อน

    Great Tutorial 🥰🥰

  • @superstarmuthu
    @superstarmuthu 3 ปีที่แล้ว +2

    you are a awesome teacher

  • @Hamza-zc2cy1xr3m
    @Hamza-zc2cy1xr3m ปีที่แล้ว

    thanks bro, nice explaining

  • @aman7555
    @aman7555 2 ปีที่แล้ว

    Excellent content as always!

  • @mattunlu8916
    @mattunlu8916 2 ปีที่แล้ว

    thank you . i liked the way you teach lot. clear , wise and lot of knowledge! for instance you log ' [...args].toString() and. `[args[0]` . these are little things but demonstrate teaching effort of you

  • @quietcorner5989
    @quietcorner5989 ปีที่แล้ว

    Hey dave it was hard for me to understant the last example ,especially when u did implement bind to create a new function curried and why u did put null in the first argument ,and what curried function also was used for in that case,it's a little bit complicated if u could please help me out with that

  • @JohnnysaidWhat
    @JohnnysaidWhat ปีที่แล้ว +1

    Curry wasn’t too hard but the function that makes curry functions was 🤯

  • @macmacmac740
    @macmacmac740 6 หลายเดือนก่อน

    Great explanation.
    Question.
    In the last example, how come the function
    const total = (x, y, z) => x + y + z
    when passed as argument as curry(total) and when we get fn.length in curry definition, it gives 3?
    Shouldn't it give 1 because we have passed function "total" entirely as an arg to "curry" and not (x, y, z)
    Thanks in advance.

  • @aeronwolfe7072
    @aeronwolfe7072 ปีที่แล้ว

    thanks SO much for the excellent content. I've been a web designer and IT person my whole life, but like a lot of 'web designers', JavaScript in the early days was hard, the books were daunting, and I of course am familiar with how to add it too my pages, get it working, and write the most basic stuff. but getting deeply into it, has never been a serious goal. but last year, I was forced to learn to maintain an application written in angular/typescript. so I learned it mostly. and that got me into trying to learn react. the more tutorials in react I started, I realized no. I need to obviously master the language first! so here I am! lol. your videos are really helping me to understand some of the more tricky aspects of JS. so, about currying functions... are these techniques used in modern frontend design very much? if I understood the video correctly, the parameters of the curried functions can be passed in separately. so does that mean at different times in the future? is this somehow related to async/await, or am I thinking about it wrong? I guess I am trying to understand where and how these are used. I guess I'll watch it again lol. thanks again for the amazing content!

    • @DaveGrayTeachesCode
      @DaveGrayTeachesCode  ปีที่แล้ว +1

      You're welcome! When currying, you can create a partial - a function that has not received everything it needs yet. That is different than async / await which I cover in detail here: th-cam.com/video/VmQ6dHvnKIM/w-d-xo.html

  • @MrVipulLal
    @MrVipulLal 2 ปีที่แล้ว

    Best explanation. Thanks!

  • @mikoajwroblewski6793
    @mikoajwroblewski6793 2 ปีที่แล้ว +15

    Is it just me or most intermediate programmers feels dazed & confused while learning this topic?

    • @DaveGrayTeachesCode
      @DaveGrayTeachesCode  2 ปีที่แล้ว +5

      It can take awhile to fully comprehend the more advanced topics. No worries. Take your time. You've got this! 💯🚀

  • @user-cp4bv5wf1o
    @user-cp4bv5wf1o ปีที่แล้ว

    Hello, sir! I have one question. In “curry” example, I’ve wrote code as same as yours, but in console, I have error: “Uncaught ReferenceError: curried is not defined”.
    When I rewrote the code the following way:
    const curry = (fn) => {
    return function curried(...args) {
    if (fn.length !== args.length) {
    return curried.bind(null, ...args);
    }
    return fn(...args);
    }
    }
    the error is disappear. Why the code you had wrote is working properly? Thanks you in advanced!
    P. S. I've understood that using strict mode, and that was a problem.

  • @kevinrobertandrews
    @kevinrobertandrews 2 ปีที่แล้ว +5

    Hi Dave, thanks for making this video. I've seen a few vids on currying and I am still wondering is there a situation where currying would be preferred over regular function calls? Or is this really just a stylistic choice?

    • @DaveGrayTeachesCode
      @DaveGrayTeachesCode  2 ปีที่แล้ว +4

      Great question, Kevin! It is useful when following a functional programming approach - but not necessary as JS does accept more than one parameter in a function (as opposed to Haskell). That said, here is a good quote on the practical application of currying followed by the link to the original source: "Currying is a type of partial function application. We can use its returned functions to make a lighter version of an existing function. It’s helpful when we have many places that use a function with exactly the same way. Our implementation will be shorter and more readable." huynvk.dev/blog/currying-in-javascript-and-its-practical-usage Thanks for asking! 💯🙏

  • @jesuswalks1101
    @jesuswalks1101 3 ปีที่แล้ว +1

    Best teacher)

  • @haritjoshi878
    @haritjoshi878 ปีที่แล้ว

    We can do this to do for variable length args for curry function:
    const curry = (fn) => {
    let curriedFunc;
    let len = 0;
    return curriedFunc = (...args) => {
    if(args.length === len) return fn(...args);
    len = args.length;
    return curriedFunc.bind(null, ...args);
    }
    };
    const total = (...args) => args.reduce((prev, curr) => prev + curr, 0);
    const sum = curry(total);
    console.log(sum(1)(2)(3)());
    Output: 6
    So the big idea is that build the args list from args.length === 0 till the args.length === m where m is the total number for which you the sum and once that list is generated add 'em up and for that we have the variable len = 0 as len

  • @doniaelfouly4142
    @doniaelfouly4142 2 หลายเดือนก่อน

    thanks

  • @sushantkumarrout2198
    @sushantkumarrout2198 ปีที่แล้ว

    You are just awesome

  • @pixobit5882
    @pixobit5882 2 ปีที่แล้ว

    Hi, isn't it simpler and cleaner (for the order example) to just use a builder function?

    • @DaveGrayTeachesCode
      @DaveGrayTeachesCode  2 ปีที่แล้ว

      Possibly. I made this video last summer. One thing I like about programming is there is usually more than one way to arrive at a result. The examples here are for showing how currying works, but I am sure they are not the only way to reach that result.

  • @fernandomatias8382
    @fernandomatias8382 ปีที่แล้ว

    Curry functions can be considered decorator functions and/or HOF (Higher Order Functions)?

    • @DaveGrayTeachesCode
      @DaveGrayTeachesCode  ปีที่แล้ว +1

      Yes, but saying it is curried or is a curry function gives a more explicit meaning. We have many liquids for example, but saying something is water gives a more explicit meaning.

  • @1000ylovers
    @1000ylovers 2 ปีที่แล้ว

    what VS Code extension do you use? it uses different colors for different {}, this is awesome

    • @DaveGrayTeachesCode
      @DaveGrayTeachesCode  2 ปีที่แล้ว

      At the time I made this video last year, I was using Bracket Pair Colorizer 2. It is now deprecated because VS Code added this functionality without the need of an extension. There are directions for how to enable native bracket matching in VS Code on the extension page (which was very nice of the developer!): marketplace.visualstudio.com/items?itemName=CoenraadS.bracket-pair-colorizer-2

  • @ahmad-murery
    @ahmad-murery 3 ปีที่แล้ว +1

    This is a nice but a bit complicated topic,
    after getting some understanding on the various ways of creating a function, the hard part now is to remember the names of all these concepts🤯😵
    one use case for currying could be 2 factor authentication, approval of some kind of documents where the hierarchy of signing the document is required, I think 🤔
    Thanks Dave, you look so hungry today, I mean awesome 😁

    • @DaveGrayTeachesCode
      @DaveGrayTeachesCode  3 ปีที่แล้ว +2

      You are correct, my friend! And yes, that might be a good application for currying using composition. I plan to cover a bit more on functional composition soon. Thanks for the comment! 💯🙏

    • @ahmad-murery
      @ahmad-murery 3 ปีที่แล้ว +1

      @@DaveGrayTeachesCode I wish I can support you more but things are going crazy where I am
      Regards

    • @DaveGrayTeachesCode
      @DaveGrayTeachesCode  3 ปีที่แล้ว +1

      @@ahmad-murerythank you 🙏 Hang in there!

  • @RC-zf7hp
    @RC-zf7hp ปีที่แล้ว

    Hi, thank you for your great explanation. My question is what is the sense of currying if JS can take multiple arguments already? In what real-life applications or use of currying? Is the use of the partial application the most common way we use currying?

    • @DaveGrayTeachesCode
      @DaveGrayTeachesCode  ปีที่แล้ว +1

      Good article on this topic: medium.com/dailyjs/why-the-fudge-should-i-use-currying-84e4000c8743

    • @RC-zf7hp
      @RC-zf7hp ปีที่แล้ว

      @@DaveGrayTeachesCode Thank you for your quick reply. Your videos are great! Subscribed already.

    • @RC-zf7hp
      @RC-zf7hp ปีที่แล้ว

      @@DaveGrayTeachesCode Thank you, I kinda get it now. No wonder, you mentioned the function composition. Does it mean, it is more for the readability of the functions, looks like more of following the DRY principle?

  • @user-yr6zg7ux3k
    @user-yr6zg7ux3k 2 ปีที่แล้ว

    Thanks a lot for making this wonderful video! I watched at least three times until I understand the basic concept.
    But I have a question, at 12:16, why completeOrder still has access to function processOrder and even calls that?

    • @DaveGrayTeachesCode
      @DaveGrayTeachesCode  2 ปีที่แล้ว +1

      Notice both processOrder and addCustomer take in completeOrder as an argument. We have curried the "chain" of functions and you do so in the reverse order they will be called. Also, notice the return in both addCustomer and processOrder... they return a function call with arguments spread in. Notice the order of returned values in the console as well. I think if you experiment with this code, you will see what is happening. It is not easy to comprehend right away.

    • @user-yr6zg7ux3k
      @user-yr6zg7ux3k 2 ปีที่แล้ว

      @@DaveGrayTeachesCode
      Thanks for your reply!
      I played around with your example code and I think I have a better understanding of the concept.
      As I understanding, when we set new value of completeOrder to processOrder(completeOrder), like in line 188, now the completeOrder is actually a function with argument (…args) returned from processOrder. And then we update the value of completeOrder by passing addCustomer(completeOrder), like in line 190, at the moment the function addCustomer gets called and return another function. After all previous steps, when we call completeOrder we also invoke addCustomer and processOrder functions (because of closure).
      Is my understanding correct?

    • @DaveGrayTeachesCode
      @DaveGrayTeachesCode  2 ปีที่แล้ว +1

      @@user-yr6zg7ux3k I think you've got it! Good job!

    • @user-yr6zg7ux3k
      @user-yr6zg7ux3k 2 ปีที่แล้ว

      I really appreciate your time and excellent clarification!

  • @zhala3860
    @zhala3860 2 ปีที่แล้ว

    Hello.Great video! Thankss. But I do not understand 7:23. I wrote the same thing but it does not work. Why idk (
    Is this the same code like you.ve written?
    const updateElemText = id => content => document.querySelector(`#${id}`).textContent = content
    const updateHeaderText = updateElemText("header")
    updateHeaderText("Hello world")

    • @DaveGrayTeachesCode
      @DaveGrayTeachesCode  2 ปีที่แล้ว

      Do you have an HTML element with the id equal to "header" ? You pass that id value to the updateElemText call first when we define updateHeaderText. At that point, updateElemText is a partial and that is what updateHeaderText is equal to. It does not complete until we pass the 2nd argument which is the content parameter. We pass that as "Hello world" when we call updateHeaderText.

  • @TheLucidWay
    @TheLucidWay 2 ปีที่แล้ว +1

    Could you please elaborate on what happens after 'return curried.bind(null, ...args)' gets executed? Is it being called again but with more arguments until it reaches args.length? I understand that a new function is created, but is it being called at the same time which triggers it to call itself? Sorry, but I'm kinda struggling with understanding the currying process.

    • @DaveGrayTeachesCode
      @DaveGrayTeachesCode  2 ปีที่แล้ว +1

      Good question and no need to apologize! This is complex stuff! You are asking about the curry function at (13:00) that we can use to curry other functions. You are right about nearly everything except the part where you say "triggers it to call itself". Bind does create the new function, but it doesn't call itself. It is essentially already being called just like when we return any function as a decorator function. We're returning curried as the function that will be called on line 246. We're binding to curried so the new function gets called as one of the functions in the curry process. It's ok to take time to digest all of this. I know it is more complex than most! Again, good question! 💯

    • @TheLucidWay
      @TheLucidWay 2 ปีที่แล้ว

      @@DaveGrayTeachesCode "We're binding to curried so the new function gets called as one of the functions in the curry process. " This cleared it up for me. Currying is a bit of a mind job, kinda like recursion, but it's starting to make more sense. Thanks for taking the time to explain it to me. I really appreciate it. Not sure if you're in the states, but if you are, I hope you have a Happy Thanksgiving!

    • @DaveGrayTeachesCode
      @DaveGrayTeachesCode  2 ปีที่แล้ว +1

      @@TheLucidWay thank you! And glad I could help!

  • @RR-et6zp
    @RR-et6zp ปีที่แล้ว

    Currying = a function that takes multiple arguments and puts them into a function that takes them one at a time. a function that takes multiple arguments and puts them into a function that takes them one at a time

  • @neithanm
    @neithanm 2 ปีที่แล้ว

    Great content as usual. Maybe I'm being picky but you can hear some room echo, if you could upgrade your mic, golden...

    • @DaveGrayTeachesCode
      @DaveGrayTeachesCode  2 ปีที่แล้ว +1

      You're right. I have since changed rooms and audio treatments. Big difference!

    • @neithanm
      @neithanm 2 ปีที่แล้ว

      ​@@DaveGrayTeachesCode that's awesome. Most of the time my projects consist of a handful of files using modular classless OOP but it looks a bit messy. I've been looking for videos on this, inspiring repos...Can you help? :)

    • @DaveGrayTeachesCode
      @DaveGrayTeachesCode  2 ปีที่แล้ว

      @@neithanm nothing specific comes to mind to share. You might search for file organization patterns. There are lots of approaches.

  • @MikeMols
    @MikeMols 3 ปีที่แล้ว

    you are just as awesome as Greta Van Fleet in this tutorial. Thanks man 🤘

  • @narenk8077
    @narenk8077 2 ปีที่แล้ว

    Which vscode extension your using

    • @DaveGrayTeachesCode
      @DaveGrayTeachesCode  2 ปีที่แล้ว

      Been awhile since this video so not sure what it was then, but right now I use the Github theme extension.

    • @narenk8077
      @narenk8077 2 ปีที่แล้ว

      @@DaveGrayTeachesCode currently I am seeing highlight the curly braces

  • @aliciapeter562
    @aliciapeter562 3 ปีที่แล้ว

    Perfect 👌

    • @DaveGrayTeachesCode
      @DaveGrayTeachesCode  3 ปีที่แล้ว

      Thank you! 🙏

    • @aliciapeter562
      @aliciapeter562 3 ปีที่แล้ว

      @@DaveGrayTeachesCode Hi Dave , I what book will you recommend for JavaScript & CSS , or What textbook is used in school . Thank looot .

    • @DaveGrayTeachesCode
      @DaveGrayTeachesCode  3 ปีที่แล้ว

      @@aliciapeter562 I do not have a book recommendation for CSS although there may be a good one out there. For Javascript, I really like Eloquent Javascript. The 3rd edition is free here: eloquentjavascript.net/

    • @aliciapeter562
      @aliciapeter562 3 ปีที่แล้ว

      @@DaveGrayTeachesCode Thank you

  • @Khaled-bs7zc
    @Khaled-bs7zc 2 ปีที่แล้ว

    I got lost at when the curry function started iterating through the arguments. What's the source behind the iteration? The ...args being passed are x, y, z at the time curried runs right? How does curry know that the arguments of the function are what's being passed as args?

    • @DaveGrayTeachesCode
      @DaveGrayTeachesCode  2 ปีที่แล้ว

      At 11:45 you should see 3 functions. Both "addCustomer" and "processOrder" are curried to create partials. This means they receive a function represented as fn but they wont' complete until they receive the 2nd parameter represented as (...args). Below that, you'll see I build the order of the functions in the reverse order I want them to complete. This isn't easy to grasp at first. Take some time and play around with the code.

    • @Khaled-bs7zc
      @Khaled-bs7zc 2 ปีที่แล้ว

      ​@@DaveGrayTeachesCode I think you're also recursing at 14:02 where curried is binding itself. What I don't get though is why we first pass one parameter then 2 then 3.
      Edit: I was looking at it all upside down. I was imagining the iteration happening while curry() was actually currying 'total' and not when curriedTotal was running. Thanks for the great video

  • @dibyadash3356
    @dibyadash3356 ปีที่แล้ว

    One question is whether it is really necessary to have one parameter while writing a currying function.

    • @DaveGrayTeachesCode
      @DaveGrayTeachesCode  ปีที่แล้ว +1

      Parameters are part of the point which also lets you create partials. Here's a great article that dives into it all, too: medium.com/javascript-scene/curry-and-function-composition-2c208d774983

  • @kabuqq
    @kabuqq 2 ปีที่แล้ว

    I confused that why the args.length increases. 17:20

    • @DaveGrayTeachesCode
      @DaveGrayTeachesCode  2 ปีที่แล้ว

      Each time an argument is passed to the function call, args.length will increase. When it receives only 1 or 2 parameters, it is a partial. When it receives all 3, it will execute the function.

  • @Hamzaelbouti
    @Hamzaelbouti ปีที่แล้ว

    Wawoooo 😁

  • @yunlin3980
    @yunlin3980 ปีที่แล้ว

    there's something not looking right on the customer order example. it's not why curry's definition tells us: Currying is a transformation of functions that translates a function from callable as f(a, b, c) into callable as f(a)(b)(c). it's more like a decorator like the author says.

  • @vladvoloshenko5701
    @vladvoloshenko5701 2 ปีที่แล้ว

    thank you from Russia:)

  • @abdelrahman5094
    @abdelrahman5094 8 หลายเดือนก่อน

    why would anyone write code in this way ?

  • @adilmughal2251
    @adilmughal2251 ปีที่แล้ว

    I found that last concepts were too tricky.

  • @anubhavgupta4917
    @anubhavgupta4917 ปีที่แล้ว

    Simply I wanna touch ur feet, sir. You made the concept very easy.

  • @josersleal
    @josersleal ปีที่แล้ว

    anyone that read clean code has nightmares ooking at this. just because its there dont mean you have to use it. like having a weapon.

  • @mocococo2877
    @mocococo2877 ปีที่แล้ว

    Well, what is the purpose of all that except playing Curry games ?
    Everything you showed could be achieved in other simpler ways.
    I hope you understand I am blaming the overall trend not you personally.
    Thank you and greetings from Bulgaria.
    Updated : Once I wrote my question I saw similar one and the answer was "... It’s helpful when we have many places that use a function with exactly the same way. Our implementation will be shorter and more readable."
    Ughhhh ... well, OK.

  • @perfect.stealth
    @perfect.stealth 2 ปีที่แล้ว

    I know classic JS but this makes 0 sense to me tbh. I feel stupid

    • @DaveGrayTeachesCode
      @DaveGrayTeachesCode  2 ปีที่แล้ว +1

      No need to feel bad. This is advanced JS. Take it slow. A little progress every day 💯

  • @aya2222
    @aya2222 2 ปีที่แล้ว

    I watched at least 4times but still can't follow from 7:39....feel stupid.

    • @DaveGrayTeachesCode
      @DaveGrayTeachesCode  2 ปีที่แล้ว +1

      Don't feel stupid. This is advanced stuff. Play around with it a little bit. Come back to it tomorrow. All good things come with a little time. You got this!

    • @aya2222
      @aya2222 2 ปีที่แล้ว +1

      ​@@DaveGrayTeachesCode why do you need to reassign completeOrder = processOrder(completeOrder)?
      I tried let order = processOrder(completeOrder) instead of reassign to completeOrder, and it worked fine. And why do you need to parentheses like ( processOrder(completeOrder))? I think it works fine without it, too. And at completeOrder = (addCustomer(completeOrder)), it means (addCustomer(processOrder(completeOrder))? I'm sorry for many questions, but I watched 10times and can't figure out....I really want to understand this.

  • @derrick3534
    @derrick3534 ปีที่แล้ว

    Wtf did I just watch

  • @KingUnity22
    @KingUnity22 2 ปีที่แล้ว

    Dave, bro, brush your teeth. Maybe invest in some whitening strips or sumn.

    • @DaveGrayTeachesCode
      @DaveGrayTeachesCode  2 ปีที่แล้ว +4

      At the time I was playing around with the color filtering for the image. Trying to get a better skin tone because I am pale but I guess I didn't pay attention to my teeth color tone! Oh well. That's a bit harsh but I will pay more attention next time.

    • @KingUnity22
      @KingUnity22 2 ปีที่แล้ว

      @@DaveGrayTeachesCode I figured it was the filtering based on the colors in the background.