Last active
February 9, 2019 17:55
-
-
Save gaganjakhotiya/f6f6e8ab09c36b86dbae4502d9e39038 to your computer and use it in GitHub Desktop.
Functional programming in JavaScript
This file contains 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
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