Skip to content

Instantly share code, notes, and snippets.

@lili21
Created August 19, 2017 04:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lili21/ec1e5ce7985a464183a3c8c2e10d9a90 to your computer and use it in GitHub Desktop.
Save lili21/ec1e5ce7985a464183a3c8c2e10d9a90 to your computer and use it in GitHub Desktop.
infinite curry
function curry(fn) {
var _args = []
return function _fn (...args) {
_args = [..._args, ...args]
if (args.length) {
return _fn
} else {
const r = _args.reduce(fn)
_args = []
return r
//return (_args.reduce(fn))
}
}
}
add = curry((a, b) => a + b)
console.log(add(1, 2, 3)())
console.log(add(1)(2)(3, 4)())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment