Skip to content

Instantly share code, notes, and snippets.

@jjsub
Last active April 29, 2016 18:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jjsub/f79a20d44f3c9d9c85dcd7024cfb68df to your computer and use it in GitHub Desktop.
Save jjsub/f79a20d44f3c9d9c85dcd7024cfb68df to your computer and use it in GitHub Desktop.
Learning javascript curry
// Learning javascript curry
// see http://www.sitepoint.com/currying-in-functional-javascript/
/*Briefly, currying is a way of constructing functions that allows partial application of a function’s arguments.
What this means is that you can pass all of the arguments a function is expecting and get the result,
or pass a subset of those arguments and get a function back that’s waiting for the rest of the arguments.
It really is that simple. */
// Example
var saludosCurry = function(saludo) {
return function(nombre) {
console.info(saludo + " , " + nombre);
};
};
var saludo = saludosCurry("Hola");
saludo("Pepe"); // Hola, Pepe
/* We can also call the original curried function directly, just by passing each of the parameters in a separate set of
parentheses, one right after the other: */
saludosCurry("Hola")("Juan"); // Hola, Juan
//cool
@jjsub
Copy link
Author

jjsub commented Apr 29, 2016

We can also call the original curried function directly, just by passing each of the parameters in a separate set of parentheses, one right after the other:

saludosCurry("Hola")("Juan"); // Hola, Juan

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment