Skip to content

Instantly share code, notes, and snippets.

@m3g4p0p
Last active December 17, 2016 18:50
Show Gist options
  • Save m3g4p0p/9c0656ec6563f2caf2c1ee8f8853c5ca to your computer and use it in GitHub Desktop.
Save m3g4p0p/9c0656ec6563f2caf2c1ee8f8853c5ca to your computer and use it in GitHub Desktop.
JS currying
const curry = (fn, thisArg) => function accumulate (...args) {
return args.length < fn.length
? accumulate.bind(null, ...args)
: fn.apply(thisArg, args)
}
const fn = (a, b, c) => a + b + c
curry(fn)(1)(2)(3) // 6
curry(fn)(1)(2, 3) // 6 etc...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment