-
Notifications
You must be signed in to change notification settings - Fork 1
/
pluck.ts
39 lines (37 loc) · 1.77 KB
/
pluck.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
import {map, Operation} from 'iter-ops';
export function pluck<T>(): Operation<T, T>;
export function pluck<T, K1 extends keyof T>(k1: K1): Operation<T, T[K1]>;
export function pluck<T, K1 extends keyof T, K2 extends keyof T[K1]>(k1: K1, k2: K2): Operation<T, T[K1][K2]>;
export function pluck<T, K1 extends keyof T, K2 extends keyof T[K1], K3 extends keyof T[K1][K2]>(k1: K1, k2: K2, k3: K3): Operation<T, T[K1][K2][K3]>;
export function pluck<T,
K1 extends keyof T,
K2 extends keyof T[K1],
K3 extends keyof T[K1][K2],
K4 extends keyof T[K1][K2][K3]>(k1: K1, k2: K2, k3: K3, k4: K4): Operation<T, T[K1][K2][K3][K4]>;
export function pluck<T,
K1 extends keyof T,
K2 extends keyof T[K1],
K3 extends keyof T[K1][K2],
K4 extends keyof T[K1][K2][K3],
K5 extends keyof T[K1][K2][K3][K4]>(k1: K1, k2: K2, k3: K3, k4: K4, k5: K5): Operation<T, T[K1][K2][K3][K4][K5]>;
export function pluck<T,
K1 extends keyof T,
K2 extends keyof T[K1],
K3 extends keyof T[K1][K2],
K4 extends keyof T[K1][K2][K3],
K5 extends keyof T[K1][K2][K3][K4],
K6 extends keyof T[K1][K2][K3][K4][K5]>(k1: K1, k2: K2, k3: K3, k4: K4, k5: K5, k6: K6): Operation<T, T[K1][K2][K3][K4][K5][K6]>;
export function pluck<T,
K1 extends keyof T,
K2 extends keyof T[K1],
K3 extends keyof T[K1][K2],
K4 extends keyof T[K1][K2][K3],
K5 extends keyof T[K1][K2][K3][K4],
K6 extends keyof T[K1][K2][K3][K4][K5]>(k1: K1, k2: K2, k3: K3, k4: K4, k5: K5, k6: K6, ...rest: string[]): Operation<T, unknown>;
export function pluck<T>(...properties: string[]): Operation<T, unknown>;
/**
* Maps each value to its specified nested property.
*/
export function pluck<T, R>(...props: string[]): Operation<T, R> {
return map(a => props.reduce((p: any, c: string) => p && p[c], a));
}