Created
October 28, 2013 15:45
-
-
Save joshbeckman/7199231 to your computer and use it in GitHub Desktop.
Curried Functions
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
function add (verb, a, b) { | |
return "The " + verb + " of " + a + ' and ' + b + ' is ' + (a + b) | |
} | |
add('sum', 5, '6') | |
//=> 'The sum of 5 and 6 is 11' | |
// Here is the curried version: | |
function addCurried (verb) { | |
return function (a) { | |
return function (b) { | |
return "The " + verb + " of " + a + ' and ' + b + ' is ' + (a + b) | |
} | |
} | |
} | |
addCurried('total')(6)(5) | |
//=> 'The total of 6 and 5 is 11' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment