Example 1 — Official: takesTwoArgs
The wrapper has length 1, so the second argument never arrives.
function takesTwoArgs(a, b) {
return [a, b];
}
const takesOneArg = R.unary(takesTwoArgs);
console.log(takesTwoArgs.length); // → 2
console.log(takesTwoArgs(1, 2)); // → [1, 2]
console.log(takesOneArg.length); // → 1
console.log(takesOneArg(1, 2)); // → [1, undefined] How It Works
- Original.
takesTwoArgsdeclares two parameters, so its length is2. - Wrap.
R.unaryreturns a function with length1. - Call.
takesOneArg(1, 2)forwards only1. - Result.
bis missing, so it isundefined.
