Last active
June 6, 2016 14:43
-
-
Save obenjiro/b0becab72178fbdca4f6 to your computer and use it in GitHub Desktop.
One lame autoCurry implementation
This file contains hidden or 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
| function auto_curry(f) { | |
| return function() { | |
| var args = []; | |
| args.push.apply(args, arguments); | |
| var next = function() { | |
| args.push.apply(args, arguments); | |
| if (f.length === args.length) { | |
| return f.apply(this, args); | |
| } else { | |
| return next; | |
| } | |
| }; | |
| if (f.length === args.length) { | |
| return f.apply(this, args); | |
| } else { | |
| return next; | |
| } | |
| }; | |
| } | |
| function sum(a,b){ | |
| return a + b; | |
| } | |
| var asum = auto_curry(sum); | |
| document.body.innerHTML = asum(1)(4) + asum(1, 4); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment