Example 1 — Official addFour
Wrap a chain of four one-argument functions, then pass all four numbers in one call.
const addFour = a => b => c => d => a + b + c + d;
const uncurriedAddFour = R.uncurryN(4, addFour);
console.log(uncurriedAddFour(1, 2, 3, 4)); // 10 How It Works
- Count the layers.
addFourhas four arrows, sonis4. - Wrap once.
R.uncurryN(4, addFour)returns a new function that expects four arguments. - Feed each layer. Ramda passes
1to the first arrow,2to the next, then3and4. - Result. The last layer adds them up:
1 + 2 + 3 + 4=10.
