forked from plotly/dash
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patharrayZipMap.ts
46 lines (35 loc) · 1.04 KB
/
arrayZipMap.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
import * as R from 'ramda';
type Array<T> = T[];
export function arrayMap<T1, TR>(
a1: Array<T1>,
cb: (d1: T1, i: number) => TR
) {
const mapArray = R.addIndex<T1, TR>(R.map);
return mapArray((iValue, i) => cb(iValue, i), a1);
}
export function arrayMap2<T1, T2, TR>(
a1: Array<T1>,
a2: Array<T2>,
cb: (d1: T1, d2: T2, i: number) => TR
) {
const mapArray = R.addIndex<T1, TR>(R.map);
return mapArray((iValue, i) => cb(iValue, a2[i], i), a1);
}
export function arrayMap3<T1, T2, T3, TR>(
a1: Array<T1>,
a2: Array<T2>,
a3: Array<T3>,
cb: (d1: T1, d2: T2, d3: T3, i: number) => TR
) {
const mapArray = R.addIndex<T1, TR>(R.map);
return mapArray((iValue, i) => cb(iValue, a2[i], a3[i], i), a1);
}
export function arrayMapN<TR>(
cb: (i: number, ...args: any[]) => TR,
...arrays: (any[])[]
) {
const a1 = arrays.slice(0, 1);
const as = arrays.slice(1);
const mapArray = R.addIndex<any, TR>(R.map);
return mapArray((iValue, i) => cb(i, [iValue, ...as.map(a => a[i])]), a1);
}