Files
30-seconds-of-code/snippets/curry.md
Angelos Chalaris 43f8529cb9 Added samples
2017-12-12 17:50:08 +02:00

369 B

Curry

Use recursion. If the number of provided arguments (args) is sufficient, call the passed function f. Otherwise return a curried function f that expects the rest of the arguments.

const curry = f =>
  (...args) =>
    args.length >= f.length ? f(...args) : (...otherArgs) => curry(f)(...args, ...otherArgs);
// curry(Math.pow)(2)(10) -> 1024