deno.land / x / rambda@v9.1.1 / source / partitionAsync.spec.js

partitionAsync.spec.js
نووسراو ببینە
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
import { composeAsync } from './composeAsync.js'import { delay } from './delay.js'import { partitionAsync } from './partitionAsync.js'
test('with composeAsync', async () => { const predicate = async (x, i) => { await delay(100) expect(typeof i).toBe('number')
return x > 2 } const list = [ 1, 2, 3, 4, 11 ]
const result = await composeAsync(partitionAsync(predicate), x => x.filter(xx => xx < 10))(list) const expectedResult = [ [ 3, 4 ], [ 1, 2 ], ]
expect(result).toEqual(expectedResult)})
test('with array', async () => { const predicate = async (x, i) => { await delay(100) expect(typeof i).toBe('number')
return x > 2 } const list = [ 1, 2, 3, 4 ]
const result = await partitionAsync(predicate, list) const expectedResult = [ [ 3, 4 ], [ 1, 2 ], ] result expect(result).toEqual(expectedResult)})
test('with object', async () => { const predicate = (value, prop) => { expect(typeof prop).toBe('string')
return value > 2 } const hash = { a : 1, b : 2, c : 3, d : 4, }
const result = await partitionAsync(predicate)(hash) const expectedResult = [ { c : 3, d : 4, }, { a : 1, b : 2, }, ] expect(result).toEqual(expectedResult)})
test('readme example', async () => { const list = [ 1, 2, 3 ] const obj = { a : 1, b : 2, c : 3, } const predicate = x => x > 2
const result = await Promise.all([ partitionAsync(predicate, list), partitionAsync(predicate, obj), ]) const expected = [ [ [ 3 ], [ 1, 2 ] ], [ { c : 3 }, { a : 1, b : 2, }, ], ] expect(result).toEqual(expected)})
rambda

Version Info

Tagged at
2 months ago