Last active
July 7, 2018 16:16
-
-
Save tsaiDavid/fba7600ad0a96c1ad70398811068695a to your computer and use it in GitHub Desktop.
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 Function as shown in "Hardcore Functional Programming in JS" | |
function curry(fn) { | |
return function () { | |
// if there are fewer provided args than originally intended | |
if (fn.length > arguments.length) { | |
var slice = Array.prototype.slice | |
var args = slice.apply(arguments) | |
// return another fn that can 'delay' application of other args | |
return function () { | |
return fn.apply(null, args.concat(slice.apply(arguments))) | |
} | |
} | |
// otherwise, just pass along the args in full | |
return fn.apply(null, arguments) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment