deno.land / x / rambda@v9.1.1 / source / compose-spec.ts

compose-spec.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
import { add, subtract, compose, map, filter, identity, inc, negate, dissoc,} from 'rambda'
interface Input { a: string, b: string,}interface Output { c: string,}
describe('R.compose with explicit types', () => { it('with explicit types - complex', () => { const obj = { a: 'foo', b: 'bar', } interface AfterInput { a: number, } interface BeforeOutput { b: string, }
const result = compose<Input[], AfterInput, BeforeOutput, Output>( x => ({c: x.b + 'bar'}), x => ({b: x.a + 'foo'}), x => ({a: x.a.length + x.b.length}) )(obj)
result // $ExpectType Output }) it('with explicit types - correct', () => { const obj = { a: 'foo', b: 'bar', } const result = compose<Input[], Output, Output>(identity, input => { input // $ExpectType Input return input as unknown as Output })(obj) result // $ExpectType Output }) it('with explicit types - wrong', () => { const obj: Input = { a: 'foo', b: 'bar', }
// @ts-expect-error compose<string, number, Output>(identity, dissoc('b'))(obj) })})
describe('R.compose', () => { it('happy', () => { const result = compose(subtract(11), add(1), add(1))(1) result // $ExpectType number }) it('happy - more complex', () => { const result = compose( (x: number) => x + 1, (x: string) => x.length + 1 )('foo') result // $ExpectType number })
it('with R.filter', () => { const result = compose( filter<number>(x => x > 2), map(add(1)) )([1, 2, 3]) result // $ExpectType number[] })
it('with native filter', () => { const result = compose( (list: number[]) => list.filter(x => x > 2), (list: number[]) => { list // $ExpectType number[] return list }, map(add(1)) )([1, 2, 3])
result // $ExpectType number[] })
it('with void', () => { const result = compose( () => {}, () => {} )() result // $ExpectType void })})
describe('R.compose - @types/ramda tests', () => { test('complex', () => { const fn = compose( inc, inc, inc, inc, inc, inc, inc, inc, negate, Math.pow ) const result = fn(3, 4) result // $ExpectType number })})
rambda

Version Info

Tagged at
2 months ago