January 2020
Intermediate to advanced
470 pages
11h 13m
English
Let's examine yet another way of doing partial application, by using closures. (You may want to go over that topic in Chapter 1, Becoming Functional – Several Questions.) This way of doing partial application will behave in a fashion somewhat reminiscent of the curry() functions we wrote earlier in this chapter, and solve the lack of flexibility that we mentioned at the end of the previous section. Our new implementation would be as follows:
const partialByClosure = (fn, ...args) => { const partialize = (...args1) => (...args2) => { for (let i = 0; i < args1.length && args2.length; i++) { if (args1[i] === undefined) { args1[i] = args2.shift(); } } const allParams = [...args1, ...args2]; return (allParams.includes(undefined) ...Read now
Unlock full access