-
Notifications
You must be signed in to change notification settings - Fork 0
/
type_test.ts
68 lines (61 loc) · 1.31 KB
/
type_test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import assert from 'https://deno.land/x/[email protected]/index.ts'
import { pipe, pipeline, compose, composeRight, pipelineUnary, composeUnary, composeUnaryRight } from './index.js'
assert<7>(pipe(
3 as const,
x => {
assert<3>(x)
return 'x' as const
},
x => {
assert<'x'>(x)
return 7 as const
},
))
assert<
(a: 0, b: 1, c: 2) => 'y'
>(pipeline(
(a: 0, b: 1, c: 2) => [a, b, c] as const,
x => {
assert<readonly [0, 1, 2]>(x)
return 'x' as const
},
x => {
assert<'x'>(x)
return 'y' as const
},
))
assert<
(a: 0, b: 1, c: 2) => 'x4'
>(compose(
(_: 'x3') => 'x4' as const,
(_: 'x2') => 'x3' as const,
(_: 'x1') => 'x2' as const,
(_: 'x0') => 'x1' as const,
(_0: 0, _1: 1, _2: 2) => 'x0' as const,
))
assert<typeof composeRight>(pipeline)
assert<typeof pipeline>(composeRight)
assert<
(x: 'x') => 'y'
>(pipelineUnary(
(x: 'x') => [x] as const,
x => {
assert<readonly ['x']>(x)
return 'x' as const
},
x => {
assert<'x'>(x)
return 'y' as const
},
))
assert<
(x0: 'x0') => 'x5'
>(composeUnary(
(_: 'x4') => 'x5' as const,
(_: 'x3') => 'x4' as const,
(_: 'x2') => 'x3' as const,
(_: 'x1') => 'x2' as const,
(_: 'x0') => 'x1' as const,
))
assert<typeof composeUnaryRight>(pipelineUnary)
assert<typeof pipelineUnary>(composeUnaryRight)