compose

源码

https://github.com/ddzy/ts-utility-plugins/tree/master/src/ddzy/utility/function/compose

说明

从右往左执行处理器函数, 与pipe 作用相反.

源码

https://github.com/ddzy/ts-utility-plugins/tree/master/src/ddzy/utility/function

用法

index.ts
import utilityFunction from "./ddzy/utility/function";
const compose = utilityFunction.compose;
// ?
function func1() {
return func2() * 2;
}
function func2() {
return func3() * 3;
}
function func3() {
return 4;
}
const p1 = compose(func1, func2, func3);
console.log(p1); // 24
console.log('--------------------');
// ?
function func4() {
return func5() + '*' + 'yang';
}
function func5() {
return func6() + '*' + 'zhao';
}
function func6() {
return 'duan';
}
const p2 = compose(func4, func5, func6);
console.log(p2); // duan*zhao*yang