Last active
June 5, 2019 21:41
-
-
Save ashwell/53e2fe89204c74687965392209782e04 to your computer and use it in GitHub Desktop.
Simple Curry 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
export function curry( fn, arity = fn.length ) { | |
let args = []; | |
return function curriedFn( ...newArgs ) { | |
args = [ ...args, ...newArgs ]; | |
if ( args.length >= arity ) { | |
return fn( ...args ); | |
} | |
return curriedFn; | |
}; | |
} | |
export default curry; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment