Last active
March 18, 2017 09:24
-
-
Save tsuz/55fd854bd63dd5e941ce5bde458d6233 to your computer and use it in GitHub Desktop.
JavaScript Curry - curry from Haskel in JS
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 curry(/*arguments*/) { | |
function getArgs(args) { | |
return [].slice.call(args); | |
} | |
function method() { | |
return arguments; | |
} | |
var defaultArgs = getArgs(arguments); | |
return function(/*arguments*/) { | |
var newArgs = getArgs(arguments); | |
var mergedArgs = defaultArgs.concat(newArgs); | |
return method.apply(null, mergedArgs); | |
} | |
} | |
var a = curry('a', 'b'); | |
console.log('a', a); // returns a method | |
var d = a('c'); // returns 'a','b','c' | |
var e = a('e'); // returns 'a','b','e' | |
console.log('d', d); | |
console.log('e', e); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment