Skip to content

Instantly share code, notes, and snippets.

@dmitryshelomanov
Created December 11, 2017 08:19
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dmitryshelomanov/cecf815e70572832fc73a1c97b14ccf8 to your computer and use it in GitHub Desktop.
Save dmitryshelomanov/cecf815e70572832fc73a1c97b14ccf8 to your computer and use it in GitHub Desktop.
curry
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