function stir(meat: Array<any>): string {
return meat.join(",");
}
function filling(slurry: ReturnType<typeof stir>): Array<any> {
return slurry.split(",");
}
function packing(bottles: ReturnType<typeof filling>): Array<object> {
let a: Array<object> = [];
bottles.forEach((item) => {
a.push({
name: item,
});
});
return a;
}
// packing(filling(stir(["猪肉", "猪肉", "猪肉", "羊肉"])));
function compose(...fns) {
return function (num) {
return fns.reduce(function (prevValue, currFn) {
return prevValue;
}, num);
};
}
const pipeline = compose(stir, filling, packing); // 自左向右逐一执行
console.log(pipeline(["猪肉", "猪肉", "猪肉", "羊肉"]));