Files
30-seconds-of-code/snippets/curry.md
Angelos Chalaris 367ee7f390 Generic currying
2017-12-10 15:21:35 +02:00

328 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.

curry = f =>
  (...args) =>
    args.length >= f.length ? f(...args) : (...otherArgs) => curry(f)(...args, ...otherArgs)