- 동기/비동기 함수 체이닝 실행 유틸
-
const pipe = (...fns) => (arg) => fns.reduce( (result, fn) => (fn instanceof Function ? result.then(fn) : result), Promise.resolve(arg) );
-
const pipe = (...fns) => (arg) => fns.reduce((result, fn) => result.then(fn), Promise.resolve(arg)); const add = (x) => x + 1; const double = async (x) => x * 2; const subtract = (x) => x - 3; const run = pipe(add, double, subtract); run(5).then(console.log); // 5 + 1 = 6 → await double(6) = 12 → 12 - 3 = 9
-