Problems with Currying and Composition
Learn about some of the issues we might run into while using currying and composition.
We'll cover the following...
Asynchronous actions
Asynchronous tasks are the tasks that are kept running side by side by the execution of the program until they return any response.
Now, we know how to compose functions to create our software. We also know how currying can help with functions that don’t naturally fit together because they have the wrong types or number of parameters. However, we’ll still have some issues with TypeScript and JavaScript. The most important issue might be that a lot happens asynchronously. Take a look at the following code snippet:
Press + to interact
const compose = (...fns) => (...args) => {return fns.reduceRight((res, fn) => [fn.call(null, ...res)], args)[0];};const givesAPromise = (num) => Promise.resolve(num);const doubleIt = (num) => num * 2;const doubled = compose(doubleIt, givesAPromise);console.log(doubled(2));
When we run the code above, we get NaN
as the ...