Skip to Content
Mastering JavaScript Functional Programming - Second Edition
book

Mastering JavaScript Functional Programming - Second Edition

by Federico Kereki
January 2020
Intermediate to advanced
470 pages
11h 13m
English
Packt Publishing
Content preview from Mastering JavaScript Functional Programming - Second Edition

Partial currying with bind()

Similar to what we did with currying, there's a simple way to do partial currying. We will take advantage of the fact that bind() can actually fix many arguments at once:

const partialCurryingByBind = fn =>  fn.length === 0    ? fn()    : (...pp) => partialCurryingByBind(fn.bind(null, ...pp));

Compare the code to the previous curryByBind() function and you'll see the very small differences:

const curryByBind = fn =>  fn.length === 0     ? fn()     : p => curryByBind(fn.bind(null, p));

The mechanism is exactly the same. The only difference is that in our new function, we can bind many arguments at the same time, while in curryByBind() we always bind just one. We can revisit our earlier example—and the only difference is that ...

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

Mastering JavaScript Functional Programming

Federico Kereki

Publisher Resources

ISBN: 9781839213069Supplemental Content