forked from remeda/remeda
-
Notifications
You must be signed in to change notification settings - Fork 0
/
flatMapToObj.test.ts
38 lines (36 loc) · 1000 Bytes
/
flatMapToObj.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
import { flatMapToObj } from './flatMapToObj';
import { pipe } from './pipe';
describe('data_first', () => {
it('flatMapToObj', () => {
const result = flatMapToObj([1, 2, 3] as const, x =>
x % 2 === 1 ? [[String(x), x]] : []
);
expect(result).toEqual({ 1: 1, 3: 3 });
});
it('flatMapToObj.indexed', () => {
const result = flatMapToObj.indexed(['a', 'b'] as const, (x, i) => [
[x, i],
[x + x, i + i],
]);
expect(result).toEqual({ a: 0, aa: 0, b: 1, bb: 2 });
});
});
describe('data_last', () => {
it('flatMapToObj', () => {
const result = pipe(
[1, 2, 3] as const,
flatMapToObj(x => (x % 2 === 1 ? [[String(x), x]] : []))
);
expect(result).toEqual({ 1: 1, 3: 3 });
});
it('flatMapToObj.indexed', () => {
const result = pipe(
['a', 'b'] as const,
flatMapToObj.indexed((x, i) => [
[x, i],
[x + x, i + i],
])
);
expect(result).toEqual({ a: 0, aa: 0, b: 1, bb: 2 });
});
});