-1

If I chose to curry this function:

function mult(a,b,c) {
    return a * b * c;
}   

into :

function mult(a) {
   return function(b) {
       return function(c) {
            return a * b * c;
       }
   }
}

What is the benefit? Is it that if I know one or more of my args will be the same, this will save run memory rather than having to recalculate with them?

  // 99 and 2 will be args a lot

 let test = mult(99); 
 let test2 = test(2)
  
 test2(42)   // 8316
 test2(1)    // 198

and so on and so on...is that the benefit of currying?

hortenzz1
  • 33
  • 4

1 Answers1

0

The benefit of a curried function is in how you can use that function. Currying is not done for a memory or processing benefit.

It enables the use of partial function application of any number of arguments and it's useful in function composition.

This article goes into more detail: https://medium.com/javascript-scene/curry-and-function-composition-2c208d774983

It has a section "Why do we curry?"

Nick VN
  • 322
  • 3
  • 5