Example 1 — Official takesTwoArgs
Wrap a three-argument function — the sample from the Ramda docs.
const takesThreeArgs = function (a, b, c) {
return [a, b, c];
};
console.log(takesThreeArgs.length); // 3
console.log(takesThreeArgs(1, 2, 3)); // [1, 2, 3]
const takesTwoArgs = R.binary(takesThreeArgs);
console.log(takesTwoArgs.length); // 2
console.log(takesTwoArgs(1, 2, 3)); // [1, 2, undefined] How It Works
- Original arity.
takesThreeArgs.lengthis3; all three values arrive. - Wrap.
R.binaryreturns a new function with.length === 2. - Call with three. Only
1and2are forwarded;cstaysundefined. - Same return shape. The array still has three slots — the third is empty.
