Skip to content

Instantly share code, notes, and snippets.

@trygvea
Last active May 28, 2016 07:26
Show Gist options
  • Save trygvea/bacf40043be9f48ff7048e6c6503eaaa to your computer and use it in GitHub Desktop.
Save trygvea/bacf40043be9f48ff7048e6c6503eaaa to your computer and use it in GitHub Desktop.
const curry = f => (...args) =>
args.length >= f.length
? f(...args)
: (...more) => curry(f)(...args, ...more)
// Test it. If
const f = (a,b,c) => a+b+c
const g = curry(f)
// then the following holds true:
f(1,2,3) === 6 &&
g(1,2,3) === 6 &&
g(1)(2)(3) === 6 &&
g(1)(2,3) === 6 &&
g(1,2)(3) === 6
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment