Last active
April 12, 2018 04:13
-
-
Save couto/35e177283855b874d8a6 to your computer and use it in GitHub Desktop.
ES5 version of curry
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
// curry :: (* -> a) -> (* -> a) | |
const curry = (fn) => function cf(...args){ | |
return (args.length >= fn.length) ? | |
fn(...args) : | |
(...newArgs) => cf(...[...args, ...newArgs]) | |
}; |
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
/** | |
* curry | |
* | |
* @param {Function} fn | |
* @param {Object} ctx | |
* @return {Function} | |
*/ | |
var curry = function curry(fn, ctx){ | |
return function cf(){ | |
var args = [].slice.call(arguments); | |
return (args.length >= fn.length) ? | |
fn.apply(null, args) : | |
function () { | |
return cf.apply(ctx, args.concat([].slice.call(arguments))); | |
}; | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment