Skip to content

Instantly share code, notes, and snippets.

@icetan
Last active February 29, 2016 15:52
Show Gist options
  • Save icetan/901127284db65704beb4 to your computer and use it in GitHub Desktop.
Save icetan/901127284db65704beb4 to your computer and use it in GitHub Desktop.
Some quick curry patterns in ES6
// funcation tree(a, b, c) { return a + b + c; }
curry = f => x => f.length>1 ? curry(f.bind(f, x)) : f(x)
uncurry = f => function(){return [].reduce.call(arguments, (f,x) => f(x), f)}
// curry(tree)(1)(1)(1) === 3
// uncurry(curry(tree))(1, 1, 1) === 3
curry_ = f => f.apply.bind(f, f)
uncurry_ = f => function(){return f(arguments)}
// curry_(tree)([1, 1, 1]) === 3
// uncurry_(curry(tree))(1, 1, 1) === 3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment