-
-
Save dmitryshelomanov/cecf815e70572832fc73a1c97b14ccf8 to your computer and use it in GitHub Desktop.
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
const getValue = (form, fieldName) => form[fieldName] | |
const form = { | |
firstName: 'dima', | |
lastName: 'shelomanov' | |
} | |
const curry = (fn, ...args) => | |
(...currentArgs) => { | |
const allArgs = [...args, ...currentArgs] | |
return allArgs.length >= fn.length | |
? fn(...allArgs) | |
: curry(fn, ...allArgs) | |
} | |
const withForm = curry(getValue, form) | |
console.log(withForm('lastName')) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment