Last active
February 29, 2016 15:52
-
-
Save icetan/901127284db65704beb4 to your computer and use it in GitHub Desktop.
Some quick curry patterns in ES6
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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