January 2020
Intermediate to advanced
470 pages
11h 13m
English
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 ...