Skip to content

Instantly share code, notes, and snippets.

@Vterebenin
Created August 30, 2019 06:59
Show Gist options
  • Select an option

  • Save Vterebenin/9da92e3e7eccbd72fbc2f9e54eb1d994 to your computer and use it in GitHub Desktop.

Select an option

Save Vterebenin/9da92e3e7eccbd72fbc2f9e54eb1d994 to your computer and use it in GitHub Desktop.
function curry(callback, ...oldParameters) {
return function(...parameters) {
const nextParameters = [...oldParameters, ...parameters]
if (nextParameters.length >= callback.length) {
return callback(...nextParameters)
}
return curry(callback, ...nextParameters)
}
}
const add = curry((a, b) => a + b)
const increment = add(1)
const decrement = add(-1)
console.log(add(1, 2)) // 3
console.log(increment(1)) // 2
console.log(decrement(1)) // 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment