Skip to content

Instantly share code, notes, and snippets.

@meowtec
Last active October 22, 2015 07:32
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 meowtec/145f3246fde7f2df1a23 to your computer and use it in GitHub Desktop.
Save meowtec/145f3246fde7f2df1a23 to your computer and use it in GitHub Desktop.
function currying(fun) {
function curryingIter(fun, len) {
if (len < 2) {
return fun
}
return curryingIter(function() {
var args = [].slice.call(arguments)
return function(x) {
args.push(x)
return fun.apply(null, args)
}
}, len - 1)
}
return curryingIter(fun, fun.length)
}
// use
function add(x, y, z) {
return x + y + z
}
var newAdd = currying(add)
newAdd(2)(3)(4) // 9
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment