Currying - jellyfish-tom/TIL GitHub Wiki
[SOURCES]
This is not going to be about Horse Grooming.
In mathematics and computer science, currying is the technique of translating the evaluation of a function that takes multiple arguments into evaluating a sequence of functions, each with a single argument.
In JS it is achieved with closures.
//Instead of this:
function multiply(a, b) {
return a * b;
}
const x = multiply(1, 2);
//We can do this:
function curriedMultiply(a) {
return function(b) {
return a * b;
}
}
const y = curriedMultiply(1)(2);
//or
const multiplyByOne = curriedMultiply(1);
const z = multiplyByOne(2);
//and
x === y === z //true, all have value 2