O'Reilly logo

Mastering JavaScript Functional Programming by Federico Kereki

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Dealing with many parameters

The idea of currying, by itself, is simple. If you need a function with, say, three parameters, instead of writing (with arrow functions) something like the following:

const make3 = (a, b, c) => String(100 * a + 10 * b + c);

You can have a sequence of functions, each with a single parameter:

const make3curried = a => b => c => String(100 * a + 10 * b + c);

Alternatively, you might want to consider them to be nested functions:

const make3curried2 = function(a) {  return function(b) {    return function(c) {      return String(100 * a + 10 * b + c);    };  };};

In terms of usage, there's an important difference in how you'd use each function. While you would call the first in usual fashion, such as make3(1,2,4), that wouldn't ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required