export default function compose(...fns) { return async x => { let res = x; for (const fn of fns) { res = await fn(res); } return res; } } // Example of usage // const f1 = x => { // return new Promise((resolve, reject) => { // setTimeout(() => { // resolve(x * 2); // }, 500); // }); // } // const f2 = x => { // return new Promise((resolve, reject) => { // setTimeout(() => { // resolve(x + 3); // }, 100); // }); // } // (async () => { // const f = compose(f1, f2); // const value = await f(7); // ((7 * 2) + 3) // console.log(value); // 17 // })();