Skip to content

Instantly share code, notes, and snippets.

@gaganjakhotiya
Last active February 9, 2019 17:55
Show Gist options
  • Save gaganjakhotiya/f6f6e8ab09c36b86dbae4502d9e39038 to your computer and use it in GitHub Desktop.
Save gaganjakhotiya/f6f6e8ab09c36b86dbae4502d9e39038 to your computer and use it in GitHub Desktop.
Functional programming in JavaScript
function curry(callable) {
return function(...args) {
if (callable.length <= args.length) {
return callable.apply(null, args)
} else {
return curry(callable).bind(null, ...args)
}
}
}
// Sample Use
const sum = (a, b) => a + b
const curriedSum = curry(sum)
const addTo10 = curriedSum(10)
const totalOf15 = addTo10(5)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment