pipe

说明

从左往右执行处理器函数, 与 compose() 相反

源码

用法

pipe.test.ts
1
import { pipe } from "../../utility/function/pipe";
2
3
describe('pipe', () => {
4
test('pipe should invoke function from left to right', () => {
5
function func1() {
6
return 2;
7
}
8
function func2() {
9
return func1() * 3;
10
}
11
function func3() {
12
return func2() * 4;
13
}
14
15
function func4() {
16
return 'duan'
17
}
18
function func5() {
19
return func4() + '*' + 'zhao';
20
}
21
function func6() {
22
return func5() + '*' + 'yang';
23
}
24
25
const received = {
26
s1: [func1, func2, func3],
27
s2: [func4, func5, func6],
28
};
29
const expected = {
30
p1: 24,
31
p2: 'duan*zhao*yang',
32
};
33
34
const r1 = pipe(...received.s1);
35
const r2 = pipe(...received.s2);
36
37
expect(r1).toBe(expected.p1);
38
expect(r2).toBe(expected.p2);
39
});
40
});
Copied!
最近更新 1yr ago
复制链接