Skip to content

Commit bcf44d9

Browse files
committed
docs: clarify the diff of pipe function in the root and async module
1 parent f16a15f commit bcf44d9

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

README.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,38 @@ const result = pipe(
4747
console.log(result); // "4"
4848
```
4949

50+
## Difference
51+
52+
The `pipe` function in the root module is equivalent to function calls without
53+
`await` like below.
54+
55+
```ts
56+
import { pipe } from "@core/pipe/pipe";
57+
58+
const a = (v: unknown) => v;
59+
const b = (v: unknown) => v;
60+
const c = (v: unknown) => v;
61+
62+
// Equivalent
63+
console.log(pipe(1, a, b, c)); // 1
64+
console.log(c(b(a(1)))); // 1
65+
```
66+
67+
The `pipe` function in the `async` module is equivalent to function calls with
68+
`await` like below.
69+
70+
```ts
71+
import { pipe } from "@core/pipe/async/pipe";
72+
73+
const a = (v: unknown) => Promise.resolve(v);
74+
const b = (v: unknown) => Promise.resolve(v);
75+
const c = (v: unknown) => Promise.resolve(v);
76+
77+
// Equivalent
78+
console.log(await pipe(1, a, b, c)); // 1
79+
console.log(await c(await b(await a(1)))); // 1
80+
```
81+
5082
## License
5183

5284
The code follows MIT license written in [LICENSE](./LICENSE). Contributors need

0 commit comments

Comments
 (0)