Skip to content

Instantly share code, notes, and snippets.

@santiago-puch-giner
Created May 5, 2016 22:22
Show Gist options
  • Save santiago-puch-giner/c9d9ab966b3881a239993ea38d6c6828 to your computer and use it in GitHub Desktop.
Save santiago-puch-giner/c9d9ab966b3881a239993ea38d6c6828 to your computer and use it in GitHub Desktop.
Currying in Javascript
// 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