Skip to Content
Mastering JavaScript Functional Programming
book

Mastering JavaScript Functional Programming

by Federico Kereki
November 2017
Intermediate to advanced
386 pages
9h 22m
English
Packt Publishing
Content preview from Mastering JavaScript Functional Programming

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 ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Mastering JavaScript Functional Programming - Second Edition

Mastering JavaScript Functional Programming - Second Edition

Federico Kereki

Publisher Resources

ISBN: 9781787287440Supplemental Content