[Javascript] Currying
2781 ワード
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 reduces function call When you need to use the same function calls a lot.
// curry(f) does the currying
function curry(f) {transform
return function(a) {
return function(b) {
return f(a, b);
};
};
}
// usage
function sum(a, b) {
return a + b;
}
let curriedSum = curry(sum);
alert( curriedSum(1)(2) ); // 3
Benefits
It reduces function call When you need to use the same function calls a lot.
Reference
この問題について([Javascript] Currying), 我々は、より多くの情報をここで見つけました https://velog.io/@suyeonme/Javascript-Curryingテキストは自由に共有またはコピーできます。ただし、このドキュメントのURLは参考URLとして残しておいてください。
Collection and Share based on the CC Protocol