Created
May 5, 2016 22:22
-
-
Save santiago-puch-giner/c9d9ab966b3881a239993ea38d6c6828 to your computer and use it in GitHub Desktop.
Currying in Javascript
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
// Snippet for currying | |
// Currying can be described as transforming a function that takes N arguments | |
// so that it can be called as a chain of N functions each taking a single argument. | |
let greetings = from => | |
message => | |
recipient => | |
'Dear ${recipient},\n\t${message}\n${from}.'; | |
let person = greetings("Jerry"); | |
let message = person("Happy Birthday!") | |
let to = message('Tom') | |
console.log(to) | |
//OR | |
console.log(greetings('Jerry')("Happy Birthday!")('Tom')); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment