UNPKG

901 BJavaScriptView Raw
1function id(v) {
2 return v;
3}
4function unionKeys(...xs) {
5 var a = new Set();
6 for (var x of xs) {
7 for (var [k] of x)
8 a.add(k);
9 }
10 return a;
11}
12function someBool(x) {
13 for (var v of x)
14 if (v)
15 return true;
16 return false;
17}
18function someTest(x, ft) {
19 var i = -1;
20 for (var v of x)
21 if (ft(v, ++i, x))
22 return true;
23 return false;
24}
25function some(x, ft = null) {
26 if (ft)
27 return someTest(x, ft);
28 else
29 return someBool(x);
30}
31function zip(xs, fm = null, ft = null, vd) {
32 var fm = fm || id, ft = ft || some;
33 var ks = unionKeys(...xs), a = new Map();
34 for (var k of ks) {
35 var ds = xs.map(x => !x.has(k));
36 if (ft(ds))
37 break;
38 var vs = xs.map(x => !x.has(k) ? vd : x.get(k));
39 a.set(k, fm(vs, k, null));
40 }
41 return a;
42}
43export default zip;