DEV Community

Randy Rivera
Randy Rivera

Posted on

Intro to Currying and Partial Application

  • This is a tough for myself since I'm still learning as I go but what I can recollect from what I read. it restructures a function so it takes one argument, then returns another function that takes the next argument, and so on.

  • Here's an example:

function add(x) {
return function(y) {
  return function(z) {
    return x + y + z;
  }
}

}
console.log(add(10)(20)(30));
Enter fullscreen mode Exit fullscreen mode
  • The add(10)(20)(30) should return 60.
  • This is useful in your program if you can't supply all the arguments to a function at one time. You can save each function call into a variable, that hold's the returned function that takes the next argument when it's available.

Top comments (0)