@hpcc-js/dataflow 8.0.1 → 8.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +43 -43
- package/README.md +530 -530
- package/dist/index.js +446 -446
- package/dist/index.js.map +1 -1
- package/dist/index.min.js +1 -1
- package/dist/index.min.js.map +1 -1
- package/lib-es6/__package__.js +3 -3
- package/lib-es6/__tests__/chain.js +48 -48
- package/lib-es6/__tests__/concat.js +16 -16
- package/lib-es6/__tests__/count.js +18 -18
- package/lib-es6/__tests__/data.js +55 -55
- package/lib-es6/__tests__/deviation.js +12 -12
- package/lib-es6/__tests__/distribution.js +18 -18
- package/lib-es6/__tests__/each.js +11 -11
- package/lib-es6/__tests__/entries.js +12 -12
- package/lib-es6/__tests__/extent.js +18 -18
- package/lib-es6/__tests__/filter.js +13 -13
- package/lib-es6/__tests__/first.js +13 -13
- package/lib-es6/__tests__/generate.js +7 -7
- package/lib-es6/__tests__/group.js +17 -17
- package/lib-es6/__tests__/histogram.js +41 -41
- package/lib-es6/__tests__/map.js +13 -13
- package/lib-es6/__tests__/max.js +29 -29
- package/lib-es6/__tests__/mean.js +9 -9
- package/lib-es6/__tests__/median.js +12 -12
- package/lib-es6/__tests__/min.js +29 -29
- package/lib-es6/__tests__/quartile.js +11 -11
- package/lib-es6/__tests__/readme.js +95 -95
- package/lib-es6/__tests__/reduce.js +14 -14
- package/lib-es6/__tests__/skip.js +13 -13
- package/lib-es6/__tests__/sort.js +18 -18
- package/lib-es6/__tests__/variance.js +12 -12
- package/lib-es6/activities/activity.js +3 -3
- package/lib-es6/activities/concat.js +9 -9
- package/lib-es6/activities/each.js +13 -13
- package/lib-es6/activities/entries.js +12 -12
- package/lib-es6/activities/filter.js +14 -14
- package/lib-es6/activities/first.js +17 -17
- package/lib-es6/activities/group.js +20 -20
- package/lib-es6/activities/histogram.js +63 -63
- package/lib-es6/activities/map.js +12 -12
- package/lib-es6/activities/skip.js +16 -16
- package/lib-es6/activities/sort.js +9 -9
- package/lib-es6/index.js +25 -25
- package/lib-es6/observers/count.js +12 -12
- package/lib-es6/observers/deviation.js +17 -17
- package/lib-es6/observers/distribution.js +35 -35
- package/lib-es6/observers/extent.js +17 -17
- package/lib-es6/observers/max.js +18 -18
- package/lib-es6/observers/mean.js +20 -20
- package/lib-es6/observers/median.js +25 -25
- package/lib-es6/observers/min.js +18 -18
- package/lib-es6/observers/observer.js +34 -34
- package/lib-es6/observers/quartile.js +37 -37
- package/lib-es6/observers/reduce.js +17 -17
- package/lib-es6/observers/variance.js +22 -22
- package/lib-es6/utils/generate.js +6 -6
- package/lib-es6/utils/pipe.js +31 -31
- package/package.json +6 -24
- package/src/__package__.ts +3 -3
- package/src/__tests__/chain.ts +85 -85
- package/src/__tests__/concat.ts +18 -18
- package/src/__tests__/count.ts +25 -25
- package/src/__tests__/data.ts +64 -64
- package/src/__tests__/deviation.ts +14 -14
- package/src/__tests__/distribution.ts +21 -21
- package/src/__tests__/each.ts +13 -13
- package/src/__tests__/entries.ts +14 -14
- package/src/__tests__/extent.ts +25 -25
- package/src/__tests__/filter.ts +16 -16
- package/src/__tests__/first.ts +15 -15
- package/src/__tests__/generate.ts +9 -9
- package/src/__tests__/group.ts +19 -19
- package/src/__tests__/histogram.ts +47 -47
- package/src/__tests__/map.ts +16 -16
- package/src/__tests__/max.ts +42 -42
- package/src/__tests__/mean.ts +11 -11
- package/src/__tests__/median.ts +14 -14
- package/src/__tests__/min.ts +42 -42
- package/src/__tests__/quartile.ts +14 -14
- package/src/__tests__/readme.ts +113 -113
- package/src/__tests__/reduce.ts +17 -17
- package/src/__tests__/skip.ts +15 -15
- package/src/__tests__/sort.ts +21 -21
- package/src/__tests__/variance.ts +14 -14
- package/src/activities/activity.ts +8 -8
- package/src/activities/concat.ts +14 -14
- package/src/activities/each.ts +19 -19
- package/src/activities/entries.ts +17 -17
- package/src/activities/filter.ts +20 -20
- package/src/activities/first.ts +20 -20
- package/src/activities/group.ts +27 -27
- package/src/activities/histogram.ts +78 -78
- package/src/activities/map.ts +18 -18
- package/src/activities/skip.ts +19 -19
- package/src/activities/sort.ts +16 -16
- package/src/index.ts +25 -25
- package/src/observers/count.ts +15 -15
- package/src/observers/deviation.ts +24 -24
- package/src/observers/distribution.ts +51 -51
- package/src/observers/extent.ts +24 -24
- package/src/observers/max.ts +24 -24
- package/src/observers/mean.ts +26 -26
- package/src/observers/median.ts +30 -30
- package/src/observers/min.ts +24 -24
- package/src/observers/observer.ts +52 -52
- package/src/observers/quartile.ts +43 -43
- package/src/observers/reduce.ts +22 -22
- package/src/observers/variance.ts +29 -29
- package/src/utils/generate.ts +6 -6
- package/src/utils/pipe.ts +74 -74
- package/types/__package__.d.ts +3 -3
- package/types/__tests__/chain.d.ts +1 -1
- package/types/__tests__/concat.d.ts +1 -1
- package/types/__tests__/count.d.ts +1 -1
- package/types/__tests__/data.d.ts +61 -61
- package/types/__tests__/deviation.d.ts +1 -1
- package/types/__tests__/distribution.d.ts +1 -1
- package/types/__tests__/each.d.ts +1 -1
- package/types/__tests__/entries.d.ts +1 -1
- package/types/__tests__/extent.d.ts +1 -1
- package/types/__tests__/filter.d.ts +1 -1
- package/types/__tests__/first.d.ts +1 -1
- package/types/__tests__/generate.d.ts +1 -1
- package/types/__tests__/group.d.ts +1 -1
- package/types/__tests__/histogram.d.ts +1 -1
- package/types/__tests__/map.d.ts +1 -1
- package/types/__tests__/max.d.ts +1 -1
- package/types/__tests__/mean.d.ts +1 -1
- package/types/__tests__/median.d.ts +1 -1
- package/types/__tests__/min.d.ts +1 -1
- package/types/__tests__/quartile.d.ts +1 -1
- package/types/__tests__/readme.d.ts +1 -1
- package/types/__tests__/reduce.d.ts +1 -1
- package/types/__tests__/skip.d.ts +1 -1
- package/types/__tests__/sort.d.ts +1 -1
- package/types/__tests__/variance.d.ts +1 -1
- package/types/activities/activity.d.ts +5 -5
- package/types/activities/concat.d.ts +3 -3
- package/types/activities/each.d.ts +4 -4
- package/types/activities/entries.d.ts +3 -3
- package/types/activities/filter.d.ts +4 -4
- package/types/activities/first.d.ts +3 -3
- package/types/activities/group.d.ts +8 -8
- package/types/activities/histogram.d.ts +17 -17
- package/types/activities/map.d.ts +4 -4
- package/types/activities/skip.d.ts +3 -3
- package/types/activities/sort.d.ts +4 -4
- package/types/index.d.ts +25 -25
- package/types/observers/count.d.ts +2 -2
- package/types/observers/deviation.d.ts +4 -4
- package/types/observers/distribution.d.ts +12 -12
- package/types/observers/extent.d.ts +4 -4
- package/types/observers/max.d.ts +4 -4
- package/types/observers/mean.d.ts +4 -4
- package/types/observers/median.d.ts +4 -4
- package/types/observers/min.d.ts +4 -4
- package/types/observers/observer.d.ts +13 -13
- package/types/observers/quartile.d.ts +5 -5
- package/types/observers/reduce.d.ts +3 -3
- package/types/observers/variance.d.ts +4 -4
- package/types/utils/generate.d.ts +1 -1
- package/types/utils/pipe.d.ts +41 -41
- package/types-3.4/__package__.d.ts +2 -2
package/dist/index.js
CHANGED
|
@@ -1,500 +1,500 @@
|
|
|
1
1
|
(function (global, factory) {
|
|
2
2
|
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
|
|
3
3
|
typeof define === 'function' && define.amd ? define(['exports'], factory) :
|
|
4
|
-
(global = global || self, factory(global[
|
|
5
|
-
}(this, (function (exports) { 'use strict';
|
|
4
|
+
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global["@hpcc-js/dataflow"] = {}));
|
|
5
|
+
})(this, (function (exports) { 'use strict';
|
|
6
6
|
|
|
7
|
-
function isSource(source) {
|
|
8
|
-
return typeof source[Symbol.iterator] === "function" || Array.isArray(source);
|
|
7
|
+
function isSource(source) {
|
|
8
|
+
return typeof source[Symbol.iterator] === "function" || Array.isArray(source);
|
|
9
9
|
}
|
|
10
10
|
|
|
11
|
-
function concatGen(concatSource) {
|
|
12
|
-
return function* (source) {
|
|
13
|
-
yield* source;
|
|
14
|
-
yield* concatSource;
|
|
15
|
-
};
|
|
16
|
-
}
|
|
17
|
-
function concat(s_or_n, concatSource) {
|
|
18
|
-
return concatSource !== undefined ? concatGen(concatSource)(s_or_n) : concatGen(s_or_n);
|
|
11
|
+
function concatGen(concatSource) {
|
|
12
|
+
return function* (source) {
|
|
13
|
+
yield* source;
|
|
14
|
+
yield* concatSource;
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
function concat(s_or_n, concatSource) {
|
|
18
|
+
return concatSource !== undefined ? concatGen(concatSource)(s_or_n) : concatGen(s_or_n);
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
-
function eachGen(callbackFn) {
|
|
22
|
-
return function* (source) {
|
|
23
|
-
let i = -1;
|
|
24
|
-
for (const item of source) {
|
|
25
|
-
callbackFn(item, ++i);
|
|
26
|
-
yield item;
|
|
27
|
-
}
|
|
28
|
-
};
|
|
29
|
-
}
|
|
30
|
-
function each(s_or_cb, callbackFn) {
|
|
31
|
-
return isSource(s_or_cb) ? eachGen(callbackFn)(s_or_cb) : eachGen(s_or_cb);
|
|
21
|
+
function eachGen(callbackFn) {
|
|
22
|
+
return function* (source) {
|
|
23
|
+
let i = -1;
|
|
24
|
+
for (const item of source) {
|
|
25
|
+
callbackFn(item, ++i);
|
|
26
|
+
yield item;
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
function each(s_or_cb, callbackFn) {
|
|
31
|
+
return isSource(s_or_cb) ? eachGen(callbackFn)(s_or_cb) : eachGen(s_or_cb);
|
|
32
32
|
}
|
|
33
33
|
|
|
34
|
-
// Array.entries
|
|
35
|
-
function entriesGen() {
|
|
36
|
-
return function* (source) {
|
|
37
|
-
let i = -1;
|
|
38
|
-
for (const item of source) {
|
|
39
|
-
yield [++i, item];
|
|
40
|
-
}
|
|
41
|
-
};
|
|
42
|
-
}
|
|
43
|
-
function entries(source) {
|
|
44
|
-
return source ? entriesGen()(source) : entriesGen();
|
|
34
|
+
// Array.entries
|
|
35
|
+
function entriesGen() {
|
|
36
|
+
return function* (source) {
|
|
37
|
+
let i = -1;
|
|
38
|
+
for (const item of source) {
|
|
39
|
+
yield [++i, item];
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
function entries(source) {
|
|
44
|
+
return source ? entriesGen()(source) : entriesGen();
|
|
45
45
|
}
|
|
46
46
|
|
|
47
|
-
function filterGen(callbackFn) {
|
|
48
|
-
return function* (source) {
|
|
49
|
-
let i = -1;
|
|
50
|
-
for (const item of source) {
|
|
51
|
-
if (callbackFn(item, ++i)) {
|
|
52
|
-
yield item;
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
};
|
|
56
|
-
}
|
|
57
|
-
function filter(s_or_cb, callbackFn) {
|
|
58
|
-
return isSource(s_or_cb) ? filterGen(callbackFn)(s_or_cb) : filterGen(s_or_cb);
|
|
47
|
+
function filterGen(callbackFn) {
|
|
48
|
+
return function* (source) {
|
|
49
|
+
let i = -1;
|
|
50
|
+
for (const item of source) {
|
|
51
|
+
if (callbackFn(item, ++i)) {
|
|
52
|
+
yield item;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
function filter(s_or_cb, callbackFn) {
|
|
58
|
+
return isSource(s_or_cb) ? filterGen(callbackFn)(s_or_cb) : filterGen(s_or_cb);
|
|
59
59
|
}
|
|
60
60
|
|
|
61
|
-
function firstGen(n) {
|
|
62
|
-
return function* (source) {
|
|
63
|
-
let i = 0;
|
|
64
|
-
for (const item of source) {
|
|
65
|
-
yield item;
|
|
66
|
-
if (++i >= n) {
|
|
67
|
-
break;
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
};
|
|
71
|
-
}
|
|
72
|
-
function first(s_or_n, n) {
|
|
73
|
-
if (!isSource(s_or_n))
|
|
74
|
-
return firstGen(s_or_n);
|
|
75
|
-
return firstGen(n)(s_or_n);
|
|
61
|
+
function firstGen(n) {
|
|
62
|
+
return function* (source) {
|
|
63
|
+
let i = 0;
|
|
64
|
+
for (const item of source) {
|
|
65
|
+
yield item;
|
|
66
|
+
if (++i >= n) {
|
|
67
|
+
break;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
function first(s_or_n, n) {
|
|
73
|
+
if (!isSource(s_or_n))
|
|
74
|
+
return firstGen(s_or_n);
|
|
75
|
+
return firstGen(n)(s_or_n);
|
|
76
76
|
}
|
|
77
77
|
|
|
78
|
-
function groupGen(groupFn) {
|
|
79
|
-
return function* (source) {
|
|
80
|
-
let i = -1;
|
|
81
|
-
const group = {};
|
|
82
|
-
for (const row of source) {
|
|
83
|
-
const key = groupFn(row, ++i);
|
|
84
|
-
if (!group[key]) {
|
|
85
|
-
group[key] = [];
|
|
86
|
-
}
|
|
87
|
-
group[key].push(row);
|
|
88
|
-
}
|
|
89
|
-
for (const key in group) {
|
|
90
|
-
yield { key, value: group[key] };
|
|
91
|
-
}
|
|
92
|
-
};
|
|
93
|
-
}
|
|
94
|
-
function group(s_or_gbf, groupByFn) {
|
|
95
|
-
return isSource(s_or_gbf) ? groupGen(groupByFn)(s_or_gbf) : groupGen(s_or_gbf);
|
|
78
|
+
function groupGen(groupFn) {
|
|
79
|
+
return function* (source) {
|
|
80
|
+
let i = -1;
|
|
81
|
+
const group = {};
|
|
82
|
+
for (const row of source) {
|
|
83
|
+
const key = groupFn(row, ++i);
|
|
84
|
+
if (!group[key]) {
|
|
85
|
+
group[key] = [];
|
|
86
|
+
}
|
|
87
|
+
group[key].push(row);
|
|
88
|
+
}
|
|
89
|
+
for (const key in group) {
|
|
90
|
+
yield { key, value: group[key] };
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
function group(s_or_gbf, groupByFn) {
|
|
95
|
+
return isSource(s_or_gbf) ? groupGen(groupByFn)(s_or_gbf) : groupGen(s_or_gbf);
|
|
96
96
|
}
|
|
97
97
|
|
|
98
|
-
function Accessor(fof, accesor) {
|
|
99
|
-
const s = fof();
|
|
100
|
-
return {
|
|
101
|
-
observe: (_, i) => {
|
|
102
|
-
s.observe(accesor(_, i), i);
|
|
103
|
-
},
|
|
104
|
-
peek: s.peek
|
|
105
|
-
};
|
|
106
|
-
}
|
|
107
|
-
// This is an pass through activity so a FlowObserver can be inserted into a pipeline ---
|
|
108
|
-
function sensor(s) {
|
|
109
|
-
return each((r, i) => s.observe(r, i));
|
|
110
|
-
}
|
|
111
|
-
// This converts a FlowObserver to an Activity ---
|
|
112
|
-
function activity(s) {
|
|
113
|
-
return function* (source) {
|
|
114
|
-
let i = -1;
|
|
115
|
-
for (const row of source) {
|
|
116
|
-
s.observe(row, ++i);
|
|
117
|
-
}
|
|
118
|
-
yield s.peek();
|
|
119
|
-
};
|
|
120
|
-
}
|
|
121
|
-
// This converts a FlowObserver to an ScalarActivity ---
|
|
122
|
-
function scalar(s) {
|
|
123
|
-
return function (source) {
|
|
124
|
-
let i = -1;
|
|
125
|
-
for (const row of source) {
|
|
126
|
-
s.observe(row, ++i);
|
|
127
|
-
}
|
|
128
|
-
return s.peek();
|
|
129
|
-
};
|
|
98
|
+
function Accessor(fof, accesor) {
|
|
99
|
+
const s = fof();
|
|
100
|
+
return {
|
|
101
|
+
observe: (_, i) => {
|
|
102
|
+
s.observe(accesor(_, i), i);
|
|
103
|
+
},
|
|
104
|
+
peek: s.peek
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
// This is an pass through activity so a FlowObserver can be inserted into a pipeline ---
|
|
108
|
+
function sensor(s) {
|
|
109
|
+
return each((r, i) => s.observe(r, i));
|
|
110
|
+
}
|
|
111
|
+
// This converts a FlowObserver to an Activity ---
|
|
112
|
+
function activity(s) {
|
|
113
|
+
return function* (source) {
|
|
114
|
+
let i = -1;
|
|
115
|
+
for (const row of source) {
|
|
116
|
+
s.observe(row, ++i);
|
|
117
|
+
}
|
|
118
|
+
yield s.peek();
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
// This converts a FlowObserver to an ScalarActivity ---
|
|
122
|
+
function scalar(s) {
|
|
123
|
+
return function (source) {
|
|
124
|
+
let i = -1;
|
|
125
|
+
for (const row of source) {
|
|
126
|
+
s.observe(row, ++i);
|
|
127
|
+
}
|
|
128
|
+
return s.peek();
|
|
129
|
+
};
|
|
130
130
|
}
|
|
131
131
|
|
|
132
|
-
function _max() {
|
|
133
|
-
let max;
|
|
134
|
-
return {
|
|
135
|
-
observe: (value, idx) => {
|
|
136
|
-
if (idx === 0) {
|
|
137
|
-
max = value;
|
|
138
|
-
}
|
|
139
|
-
else if (max < value) {
|
|
140
|
-
max = value;
|
|
141
|
-
}
|
|
142
|
-
},
|
|
143
|
-
peek: () => max
|
|
144
|
-
};
|
|
145
|
-
}
|
|
146
|
-
function max(callbackFn) {
|
|
147
|
-
return callbackFn ? Accessor(_max, callbackFn) : _max();
|
|
132
|
+
function _max() {
|
|
133
|
+
let max;
|
|
134
|
+
return {
|
|
135
|
+
observe: (value, idx) => {
|
|
136
|
+
if (idx === 0) {
|
|
137
|
+
max = value;
|
|
138
|
+
}
|
|
139
|
+
else if (max < value) {
|
|
140
|
+
max = value;
|
|
141
|
+
}
|
|
142
|
+
},
|
|
143
|
+
peek: () => max
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
function max(callbackFn) {
|
|
147
|
+
return callbackFn ? Accessor(_max, callbackFn) : _max();
|
|
148
148
|
}
|
|
149
149
|
|
|
150
|
-
function _min() {
|
|
151
|
-
let min;
|
|
152
|
-
return {
|
|
153
|
-
observe: (value, idx) => {
|
|
154
|
-
if (idx === 0) {
|
|
155
|
-
min = value;
|
|
156
|
-
}
|
|
157
|
-
else if (min > value) {
|
|
158
|
-
min = value;
|
|
159
|
-
}
|
|
160
|
-
},
|
|
161
|
-
peek: () => min
|
|
162
|
-
};
|
|
163
|
-
}
|
|
164
|
-
function min(callbackFn) {
|
|
165
|
-
return callbackFn ? Accessor(_min, callbackFn) : _min();
|
|
150
|
+
function _min() {
|
|
151
|
+
let min;
|
|
152
|
+
return {
|
|
153
|
+
observe: (value, idx) => {
|
|
154
|
+
if (idx === 0) {
|
|
155
|
+
min = value;
|
|
156
|
+
}
|
|
157
|
+
else if (min > value) {
|
|
158
|
+
min = value;
|
|
159
|
+
}
|
|
160
|
+
},
|
|
161
|
+
peek: () => min
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
function min(callbackFn) {
|
|
165
|
+
return callbackFn ? Accessor(_min, callbackFn) : _min();
|
|
166
166
|
}
|
|
167
167
|
|
|
168
|
-
function _extent() {
|
|
169
|
-
const minFO = min();
|
|
170
|
-
const maxFO = max();
|
|
171
|
-
return {
|
|
172
|
-
observe: (value, idx) => {
|
|
173
|
-
minFO.observe(value, idx);
|
|
174
|
-
maxFO.observe(value, idx);
|
|
175
|
-
},
|
|
176
|
-
peek: () => [minFO.peek(), maxFO.peek()]
|
|
177
|
-
};
|
|
178
|
-
}
|
|
179
|
-
function extent(callbackFn) {
|
|
180
|
-
return callbackFn ? Accessor(_extent, callbackFn) : _extent();
|
|
168
|
+
function _extent() {
|
|
169
|
+
const minFO = min();
|
|
170
|
+
const maxFO = max();
|
|
171
|
+
return {
|
|
172
|
+
observe: (value, idx) => {
|
|
173
|
+
minFO.observe(value, idx);
|
|
174
|
+
maxFO.observe(value, idx);
|
|
175
|
+
},
|
|
176
|
+
peek: () => [minFO.peek(), maxFO.peek()]
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
function extent(callbackFn) {
|
|
180
|
+
return callbackFn ? Accessor(_extent, callbackFn) : _extent();
|
|
181
181
|
}
|
|
182
182
|
|
|
183
|
-
function isOptionA(_) {
|
|
184
|
-
return _.buckets !== undefined;
|
|
185
|
-
}
|
|
186
|
-
function histogramGen(callbackFn, options) {
|
|
187
|
-
return function* (_source) {
|
|
188
|
-
let min;
|
|
189
|
-
let bucketSize;
|
|
190
|
-
let source;
|
|
191
|
-
if (isOptionA(options)) {
|
|
192
|
-
source = Array.isArray(_source) ? _source : [..._source];
|
|
193
|
-
const minMax = scalar(extent(callbackFn))(source);
|
|
194
|
-
if (minMax === undefined) {
|
|
195
|
-
return undefined;
|
|
196
|
-
}
|
|
197
|
-
min = minMax[0];
|
|
198
|
-
const max = minMax[1];
|
|
199
|
-
const buckets = options.buckets;
|
|
200
|
-
bucketSize = (max - min) / buckets;
|
|
201
|
-
}
|
|
202
|
-
else {
|
|
203
|
-
source = _source;
|
|
204
|
-
min = options.min;
|
|
205
|
-
bucketSize = options.range;
|
|
206
|
-
}
|
|
207
|
-
const histogram = {};
|
|
208
|
-
let maxBucketID = 0;
|
|
209
|
-
for (const row of source) {
|
|
210
|
-
const value = callbackFn(row);
|
|
211
|
-
const bucketID = Math.floor((value - min) / bucketSize);
|
|
212
|
-
if (maxBucketID < bucketID) {
|
|
213
|
-
maxBucketID = bucketID;
|
|
214
|
-
}
|
|
215
|
-
if (histogram[bucketID] === undefined) {
|
|
216
|
-
histogram[bucketID] = [];
|
|
217
|
-
}
|
|
218
|
-
histogram[bucketID].push(row);
|
|
219
|
-
}
|
|
220
|
-
const lastBucket = histogram[maxBucketID];
|
|
221
|
-
const from = min + maxBucketID * bucketSize;
|
|
222
|
-
for (let i = 0; i <= maxBucketID; ++i) {
|
|
223
|
-
// If all items in the last bucket match the "to" of the previous bucket, put them in there...
|
|
224
|
-
if (i === maxBucketID - 1 && lastBucket.every(row => from === callbackFn(row))) {
|
|
225
|
-
yield {
|
|
226
|
-
from: min + i * bucketSize,
|
|
227
|
-
to: min + (i + 1) * bucketSize,
|
|
228
|
-
value: [...(histogram[i] || []), ...lastBucket]
|
|
229
|
-
};
|
|
230
|
-
break;
|
|
231
|
-
}
|
|
232
|
-
yield {
|
|
233
|
-
from: min + i * bucketSize,
|
|
234
|
-
to: min + (i + 1) * bucketSize,
|
|
235
|
-
value: histogram[i] || []
|
|
236
|
-
};
|
|
237
|
-
}
|
|
238
|
-
};
|
|
239
|
-
}
|
|
240
|
-
function histogram(s_or_hf, hf_or_b, options) {
|
|
241
|
-
return isSource(s_or_hf) ? histogramGen(hf_or_b, options)(s_or_hf) : histogramGen(s_or_hf, hf_or_b);
|
|
183
|
+
function isOptionA(_) {
|
|
184
|
+
return _.buckets !== undefined;
|
|
185
|
+
}
|
|
186
|
+
function histogramGen(callbackFn, options) {
|
|
187
|
+
return function* (_source) {
|
|
188
|
+
let min;
|
|
189
|
+
let bucketSize;
|
|
190
|
+
let source;
|
|
191
|
+
if (isOptionA(options)) {
|
|
192
|
+
source = Array.isArray(_source) ? _source : [..._source];
|
|
193
|
+
const minMax = scalar(extent(callbackFn))(source);
|
|
194
|
+
if (minMax === undefined) {
|
|
195
|
+
return undefined;
|
|
196
|
+
}
|
|
197
|
+
min = minMax[0];
|
|
198
|
+
const max = minMax[1];
|
|
199
|
+
const buckets = options.buckets;
|
|
200
|
+
bucketSize = (max - min) / buckets;
|
|
201
|
+
}
|
|
202
|
+
else {
|
|
203
|
+
source = _source;
|
|
204
|
+
min = options.min;
|
|
205
|
+
bucketSize = options.range;
|
|
206
|
+
}
|
|
207
|
+
const histogram = {};
|
|
208
|
+
let maxBucketID = 0;
|
|
209
|
+
for (const row of source) {
|
|
210
|
+
const value = callbackFn(row);
|
|
211
|
+
const bucketID = Math.floor((value - min) / bucketSize);
|
|
212
|
+
if (maxBucketID < bucketID) {
|
|
213
|
+
maxBucketID = bucketID;
|
|
214
|
+
}
|
|
215
|
+
if (histogram[bucketID] === undefined) {
|
|
216
|
+
histogram[bucketID] = [];
|
|
217
|
+
}
|
|
218
|
+
histogram[bucketID].push(row);
|
|
219
|
+
}
|
|
220
|
+
const lastBucket = histogram[maxBucketID];
|
|
221
|
+
const from = min + maxBucketID * bucketSize;
|
|
222
|
+
for (let i = 0; i <= maxBucketID; ++i) {
|
|
223
|
+
// If all items in the last bucket match the "to" of the previous bucket, put them in there...
|
|
224
|
+
if (i === maxBucketID - 1 && lastBucket.every(row => from === callbackFn(row))) {
|
|
225
|
+
yield {
|
|
226
|
+
from: min + i * bucketSize,
|
|
227
|
+
to: min + (i + 1) * bucketSize,
|
|
228
|
+
value: [...(histogram[i] || []), ...lastBucket]
|
|
229
|
+
};
|
|
230
|
+
break;
|
|
231
|
+
}
|
|
232
|
+
yield {
|
|
233
|
+
from: min + i * bucketSize,
|
|
234
|
+
to: min + (i + 1) * bucketSize,
|
|
235
|
+
value: histogram[i] || []
|
|
236
|
+
};
|
|
237
|
+
}
|
|
238
|
+
};
|
|
239
|
+
}
|
|
240
|
+
function histogram(s_or_hf, hf_or_b, options) {
|
|
241
|
+
return isSource(s_or_hf) ? histogramGen(hf_or_b, options)(s_or_hf) : histogramGen(s_or_hf, hf_or_b);
|
|
242
242
|
}
|
|
243
243
|
|
|
244
|
-
function mapGen(callbackFn) {
|
|
245
|
-
return function* (source) {
|
|
246
|
-
let i = -1;
|
|
247
|
-
for (const item of source) {
|
|
248
|
-
yield callbackFn(item, ++i);
|
|
249
|
-
}
|
|
250
|
-
};
|
|
251
|
-
}
|
|
252
|
-
function map(s_or_cb, callbackFn) {
|
|
253
|
-
return isSource(s_or_cb) ? mapGen(callbackFn)(s_or_cb) : mapGen(s_or_cb);
|
|
244
|
+
function mapGen(callbackFn) {
|
|
245
|
+
return function* (source) {
|
|
246
|
+
let i = -1;
|
|
247
|
+
for (const item of source) {
|
|
248
|
+
yield callbackFn(item, ++i);
|
|
249
|
+
}
|
|
250
|
+
};
|
|
251
|
+
}
|
|
252
|
+
function map(s_or_cb, callbackFn) {
|
|
253
|
+
return isSource(s_or_cb) ? mapGen(callbackFn)(s_or_cb) : mapGen(s_or_cb);
|
|
254
254
|
}
|
|
255
255
|
|
|
256
|
-
function skipGen(n) {
|
|
257
|
-
return function* (source) {
|
|
258
|
-
let i = -1;
|
|
259
|
-
for (const item of source) {
|
|
260
|
-
if (++i >= n) {
|
|
261
|
-
yield item;
|
|
262
|
-
}
|
|
263
|
-
}
|
|
264
|
-
};
|
|
265
|
-
}
|
|
266
|
-
function skip(s_or_n, n) {
|
|
267
|
-
if (!isSource(s_or_n))
|
|
268
|
-
return skipGen(s_or_n);
|
|
269
|
-
return skipGen(n)(s_or_n);
|
|
256
|
+
function skipGen(n) {
|
|
257
|
+
return function* (source) {
|
|
258
|
+
let i = -1;
|
|
259
|
+
for (const item of source) {
|
|
260
|
+
if (++i >= n) {
|
|
261
|
+
yield item;
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
};
|
|
265
|
+
}
|
|
266
|
+
function skip(s_or_n, n) {
|
|
267
|
+
if (!isSource(s_or_n))
|
|
268
|
+
return skipGen(s_or_n);
|
|
269
|
+
return skipGen(n)(s_or_n);
|
|
270
270
|
}
|
|
271
271
|
|
|
272
|
-
function sortGen(compareFn) {
|
|
273
|
-
return function* (source) {
|
|
274
|
-
yield* (Array.isArray(source) ? source : [...source]).sort(compareFn);
|
|
275
|
-
};
|
|
276
|
-
}
|
|
277
|
-
function sort(s_or_cb, callbackFn) {
|
|
278
|
-
return isSource(s_or_cb) ? sortGen(callbackFn)(s_or_cb) : sortGen(s_or_cb);
|
|
272
|
+
function sortGen(compareFn) {
|
|
273
|
+
return function* (source) {
|
|
274
|
+
yield* (Array.isArray(source) ? source : [...source]).sort(compareFn);
|
|
275
|
+
};
|
|
276
|
+
}
|
|
277
|
+
function sort(s_or_cb, callbackFn) {
|
|
278
|
+
return isSource(s_or_cb) ? sortGen(callbackFn)(s_or_cb) : sortGen(s_or_cb);
|
|
279
279
|
}
|
|
280
280
|
|
|
281
|
-
function count() {
|
|
282
|
-
let count;
|
|
283
|
-
return {
|
|
284
|
-
observe: (value, idx) => {
|
|
285
|
-
if (idx === 0) {
|
|
286
|
-
count = 0;
|
|
287
|
-
}
|
|
288
|
-
++count;
|
|
289
|
-
},
|
|
290
|
-
peek: () => count
|
|
291
|
-
};
|
|
281
|
+
function count() {
|
|
282
|
+
let count;
|
|
283
|
+
return {
|
|
284
|
+
observe: (value, idx) => {
|
|
285
|
+
if (idx === 0) {
|
|
286
|
+
count = 0;
|
|
287
|
+
}
|
|
288
|
+
++count;
|
|
289
|
+
},
|
|
290
|
+
peek: () => count
|
|
291
|
+
};
|
|
292
292
|
}
|
|
293
293
|
|
|
294
|
-
function _variance() {
|
|
295
|
-
let count;
|
|
296
|
-
let mean;
|
|
297
|
-
let sum;
|
|
298
|
-
return {
|
|
299
|
-
observe: (value, idx) => {
|
|
300
|
-
if (idx === 0) {
|
|
301
|
-
count = 0;
|
|
302
|
-
mean = 0;
|
|
303
|
-
sum = 0;
|
|
304
|
-
}
|
|
305
|
-
const delta = value - mean;
|
|
306
|
-
mean += delta / ++count;
|
|
307
|
-
sum += delta * (value - mean);
|
|
308
|
-
},
|
|
309
|
-
peek: () => count > 1 ? sum / (count - 1) : undefined
|
|
310
|
-
};
|
|
311
|
-
}
|
|
312
|
-
function variance(callbackFn) {
|
|
313
|
-
return callbackFn ? Accessor(_variance, callbackFn) : _variance();
|
|
294
|
+
function _variance() {
|
|
295
|
+
let count;
|
|
296
|
+
let mean;
|
|
297
|
+
let sum;
|
|
298
|
+
return {
|
|
299
|
+
observe: (value, idx) => {
|
|
300
|
+
if (idx === 0) {
|
|
301
|
+
count = 0;
|
|
302
|
+
mean = 0;
|
|
303
|
+
sum = 0;
|
|
304
|
+
}
|
|
305
|
+
const delta = value - mean;
|
|
306
|
+
mean += delta / ++count;
|
|
307
|
+
sum += delta * (value - mean);
|
|
308
|
+
},
|
|
309
|
+
peek: () => count > 1 ? sum / (count - 1) : undefined
|
|
310
|
+
};
|
|
311
|
+
}
|
|
312
|
+
function variance(callbackFn) {
|
|
313
|
+
return callbackFn ? Accessor(_variance, callbackFn) : _variance();
|
|
314
314
|
}
|
|
315
315
|
|
|
316
|
-
function _deviation() {
|
|
317
|
-
const v = variance();
|
|
318
|
-
return {
|
|
319
|
-
observe: (value, idx) => {
|
|
320
|
-
v.observe(value, idx);
|
|
321
|
-
},
|
|
322
|
-
peek: () => {
|
|
323
|
-
const variance = v.peek();
|
|
324
|
-
return variance !== undefined ? Math.sqrt(variance) : variance;
|
|
325
|
-
}
|
|
326
|
-
};
|
|
327
|
-
}
|
|
328
|
-
function deviation(callbackFn) {
|
|
329
|
-
return callbackFn ? Accessor(_deviation, callbackFn) : _deviation();
|
|
316
|
+
function _deviation() {
|
|
317
|
+
const v = variance();
|
|
318
|
+
return {
|
|
319
|
+
observe: (value, idx) => {
|
|
320
|
+
v.observe(value, idx);
|
|
321
|
+
},
|
|
322
|
+
peek: () => {
|
|
323
|
+
const variance = v.peek();
|
|
324
|
+
return variance !== undefined ? Math.sqrt(variance) : variance;
|
|
325
|
+
}
|
|
326
|
+
};
|
|
327
|
+
}
|
|
328
|
+
function deviation(callbackFn) {
|
|
329
|
+
return callbackFn ? Accessor(_deviation, callbackFn) : _deviation();
|
|
330
330
|
}
|
|
331
331
|
|
|
332
|
-
function _mean() {
|
|
333
|
-
let total;
|
|
334
|
-
let count;
|
|
335
|
-
return {
|
|
336
|
-
observe: (value, idx) => {
|
|
337
|
-
if (idx === 0) {
|
|
338
|
-
total = value;
|
|
339
|
-
}
|
|
340
|
-
else {
|
|
341
|
-
total += value;
|
|
342
|
-
}
|
|
343
|
-
count = idx;
|
|
344
|
-
},
|
|
345
|
-
peek: () => total / (count + 1)
|
|
346
|
-
};
|
|
347
|
-
}
|
|
348
|
-
function mean(callbackFn) {
|
|
349
|
-
return callbackFn ? Accessor(_mean, callbackFn) : _mean();
|
|
332
|
+
function _mean() {
|
|
333
|
+
let total;
|
|
334
|
+
let count;
|
|
335
|
+
return {
|
|
336
|
+
observe: (value, idx) => {
|
|
337
|
+
if (idx === 0) {
|
|
338
|
+
total = value;
|
|
339
|
+
}
|
|
340
|
+
else {
|
|
341
|
+
total += value;
|
|
342
|
+
}
|
|
343
|
+
count = idx;
|
|
344
|
+
},
|
|
345
|
+
peek: () => total / (count + 1)
|
|
346
|
+
};
|
|
347
|
+
}
|
|
348
|
+
function mean(callbackFn) {
|
|
349
|
+
return callbackFn ? Accessor(_mean, callbackFn) : _mean();
|
|
350
350
|
}
|
|
351
351
|
|
|
352
|
-
function _distribution() {
|
|
353
|
-
const minFO = min();
|
|
354
|
-
const maxFO = max();
|
|
355
|
-
const meanFO = mean();
|
|
356
|
-
const varianceFO = variance();
|
|
357
|
-
return {
|
|
358
|
-
observe: (value, idx) => {
|
|
359
|
-
minFO.observe(value, idx);
|
|
360
|
-
maxFO.observe(value, idx);
|
|
361
|
-
meanFO.observe(value, idx);
|
|
362
|
-
varianceFO.observe(value, idx);
|
|
363
|
-
},
|
|
364
|
-
peek: () => {
|
|
365
|
-
const minResult = minFO.peek();
|
|
366
|
-
if (minResult === undefined)
|
|
367
|
-
return undefined;
|
|
368
|
-
const varianceResult = varianceFO.peek();
|
|
369
|
-
return {
|
|
370
|
-
min: minResult,
|
|
371
|
-
max: maxFO.peek(),
|
|
372
|
-
mean: meanFO.peek(),
|
|
373
|
-
variance: varianceResult,
|
|
374
|
-
deviation: varianceResult !== undefined ? Math.sqrt(varianceResult) : undefined
|
|
375
|
-
};
|
|
376
|
-
}
|
|
377
|
-
};
|
|
378
|
-
}
|
|
379
|
-
function distribution(callbackFn) {
|
|
380
|
-
return callbackFn ? Accessor(_distribution, callbackFn) : _distribution();
|
|
352
|
+
function _distribution() {
|
|
353
|
+
const minFO = min();
|
|
354
|
+
const maxFO = max();
|
|
355
|
+
const meanFO = mean();
|
|
356
|
+
const varianceFO = variance();
|
|
357
|
+
return {
|
|
358
|
+
observe: (value, idx) => {
|
|
359
|
+
minFO.observe(value, idx);
|
|
360
|
+
maxFO.observe(value, idx);
|
|
361
|
+
meanFO.observe(value, idx);
|
|
362
|
+
varianceFO.observe(value, idx);
|
|
363
|
+
},
|
|
364
|
+
peek: () => {
|
|
365
|
+
const minResult = minFO.peek();
|
|
366
|
+
if (minResult === undefined)
|
|
367
|
+
return undefined;
|
|
368
|
+
const varianceResult = varianceFO.peek();
|
|
369
|
+
return {
|
|
370
|
+
min: minResult,
|
|
371
|
+
max: maxFO.peek(),
|
|
372
|
+
mean: meanFO.peek(),
|
|
373
|
+
variance: varianceResult,
|
|
374
|
+
deviation: varianceResult !== undefined ? Math.sqrt(varianceResult) : undefined
|
|
375
|
+
};
|
|
376
|
+
}
|
|
377
|
+
};
|
|
378
|
+
}
|
|
379
|
+
function distribution(callbackFn) {
|
|
380
|
+
return callbackFn ? Accessor(_distribution, callbackFn) : _distribution();
|
|
381
381
|
}
|
|
382
382
|
|
|
383
|
-
function _median() {
|
|
384
|
-
let values;
|
|
385
|
-
return {
|
|
386
|
-
observe: (value, idx) => {
|
|
387
|
-
if (idx === 0) {
|
|
388
|
-
values = [];
|
|
389
|
-
}
|
|
390
|
-
values.push(value);
|
|
391
|
-
},
|
|
392
|
-
peek: () => {
|
|
393
|
-
const sorted = values.sort((l, r) => l - r);
|
|
394
|
-
const mid = sorted.length / 2;
|
|
395
|
-
if (sorted.length % 2 === 0) {
|
|
396
|
-
return (sorted[mid - 1] + sorted[mid]) / 2;
|
|
397
|
-
}
|
|
398
|
-
else {
|
|
399
|
-
return sorted[Math.floor(mid)];
|
|
400
|
-
}
|
|
401
|
-
}
|
|
402
|
-
};
|
|
403
|
-
}
|
|
404
|
-
function median(callbackFn) {
|
|
405
|
-
return callbackFn ? Accessor(_median, callbackFn) : _median();
|
|
383
|
+
function _median() {
|
|
384
|
+
let values;
|
|
385
|
+
return {
|
|
386
|
+
observe: (value, idx) => {
|
|
387
|
+
if (idx === 0) {
|
|
388
|
+
values = [];
|
|
389
|
+
}
|
|
390
|
+
values.push(value);
|
|
391
|
+
},
|
|
392
|
+
peek: () => {
|
|
393
|
+
const sorted = values.sort((l, r) => l - r);
|
|
394
|
+
const mid = sorted.length / 2;
|
|
395
|
+
if (sorted.length % 2 === 0) {
|
|
396
|
+
return (sorted[mid - 1] + sorted[mid]) / 2;
|
|
397
|
+
}
|
|
398
|
+
else {
|
|
399
|
+
return sorted[Math.floor(mid)];
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
};
|
|
403
|
+
}
|
|
404
|
+
function median(callbackFn) {
|
|
405
|
+
return callbackFn ? Accessor(_median, callbackFn) : _median();
|
|
406
406
|
}
|
|
407
407
|
|
|
408
|
-
function _quartile() {
|
|
409
|
-
let values;
|
|
410
|
-
return {
|
|
411
|
-
observe: (value, idx) => {
|
|
412
|
-
if (idx === 0) {
|
|
413
|
-
values = [];
|
|
414
|
-
}
|
|
415
|
-
values.push(value);
|
|
416
|
-
},
|
|
417
|
-
peek: () => {
|
|
418
|
-
const sorted = values.sort((l, r) => l - r);
|
|
419
|
-
const mid = sorted.length / 2;
|
|
420
|
-
let medianVal;
|
|
421
|
-
let lower;
|
|
422
|
-
let upper;
|
|
423
|
-
if (sorted.length < 2) {
|
|
424
|
-
return undefined;
|
|
425
|
-
}
|
|
426
|
-
else if (sorted.length % 2 === 0) {
|
|
427
|
-
medianVal = (sorted[mid - 1] + sorted[mid]) / 2;
|
|
428
|
-
lower = sorted.slice(0, mid);
|
|
429
|
-
upper = sorted.slice(mid);
|
|
430
|
-
}
|
|
431
|
-
else {
|
|
432
|
-
medianVal = sorted[Math.floor(mid)];
|
|
433
|
-
lower = sorted.slice(0, Math.floor(mid));
|
|
434
|
-
upper = sorted.slice(Math.ceil(mid));
|
|
435
|
-
}
|
|
436
|
-
return [sorted[0], scalar(median())(lower), medianVal, scalar(median())(upper), sorted[sorted.length - 1]];
|
|
437
|
-
}
|
|
438
|
-
};
|
|
439
|
-
}
|
|
440
|
-
function quartile(callbackFn) {
|
|
441
|
-
return callbackFn ? Accessor(_quartile, callbackFn) : _quartile();
|
|
408
|
+
function _quartile() {
|
|
409
|
+
let values;
|
|
410
|
+
return {
|
|
411
|
+
observe: (value, idx) => {
|
|
412
|
+
if (idx === 0) {
|
|
413
|
+
values = [];
|
|
414
|
+
}
|
|
415
|
+
values.push(value);
|
|
416
|
+
},
|
|
417
|
+
peek: () => {
|
|
418
|
+
const sorted = values.sort((l, r) => l - r);
|
|
419
|
+
const mid = sorted.length / 2;
|
|
420
|
+
let medianVal;
|
|
421
|
+
let lower;
|
|
422
|
+
let upper;
|
|
423
|
+
if (sorted.length < 2) {
|
|
424
|
+
return undefined;
|
|
425
|
+
}
|
|
426
|
+
else if (sorted.length % 2 === 0) {
|
|
427
|
+
medianVal = (sorted[mid - 1] + sorted[mid]) / 2;
|
|
428
|
+
lower = sorted.slice(0, mid);
|
|
429
|
+
upper = sorted.slice(mid);
|
|
430
|
+
}
|
|
431
|
+
else {
|
|
432
|
+
medianVal = sorted[Math.floor(mid)];
|
|
433
|
+
lower = sorted.slice(0, Math.floor(mid));
|
|
434
|
+
upper = sorted.slice(Math.ceil(mid));
|
|
435
|
+
}
|
|
436
|
+
return [sorted[0], scalar(median())(lower), medianVal, scalar(median())(upper), sorted[sorted.length - 1]];
|
|
437
|
+
}
|
|
438
|
+
};
|
|
439
|
+
}
|
|
440
|
+
function quartile(callbackFn) {
|
|
441
|
+
return callbackFn ? Accessor(_quartile, callbackFn) : _quartile();
|
|
442
442
|
}
|
|
443
443
|
|
|
444
|
-
function _reduce(callback, initialValue) {
|
|
445
|
-
let reduced;
|
|
446
|
-
return {
|
|
447
|
-
observe: (value, idx) => {
|
|
448
|
-
if (idx === 0) {
|
|
449
|
-
reduced = initialValue === undefined ? value : callback(initialValue, value, idx);
|
|
450
|
-
}
|
|
451
|
-
else {
|
|
452
|
-
reduced = callback(reduced, value, idx);
|
|
453
|
-
}
|
|
454
|
-
},
|
|
455
|
-
peek: () => reduced
|
|
456
|
-
};
|
|
457
|
-
}
|
|
458
|
-
function reduce(callbackFn, initialValue) {
|
|
459
|
-
return _reduce(callbackFn, initialValue);
|
|
444
|
+
function _reduce(callback, initialValue) {
|
|
445
|
+
let reduced;
|
|
446
|
+
return {
|
|
447
|
+
observe: (value, idx) => {
|
|
448
|
+
if (idx === 0) {
|
|
449
|
+
reduced = initialValue === undefined ? value : callback(initialValue, value, idx);
|
|
450
|
+
}
|
|
451
|
+
else {
|
|
452
|
+
reduced = callback(reduced, value, idx);
|
|
453
|
+
}
|
|
454
|
+
},
|
|
455
|
+
peek: () => reduced
|
|
456
|
+
};
|
|
457
|
+
}
|
|
458
|
+
function reduce(callbackFn, initialValue) {
|
|
459
|
+
return _reduce(callbackFn, initialValue);
|
|
460
460
|
}
|
|
461
461
|
|
|
462
|
-
function* generate(generatorFn, maxLen) {
|
|
463
|
-
let i = -1;
|
|
464
|
-
while (maxLen === undefined || ++i < maxLen) {
|
|
465
|
-
yield generatorFn();
|
|
466
|
-
}
|
|
462
|
+
function* generate(generatorFn, maxLen) {
|
|
463
|
+
let i = -1;
|
|
464
|
+
while (maxLen === undefined || ++i < maxLen) {
|
|
465
|
+
yield generatorFn();
|
|
466
|
+
}
|
|
467
467
|
}
|
|
468
468
|
|
|
469
|
-
const GeneratorFunction = (function* () { }).constructor;
|
|
470
|
-
function chainGen(...items) {
|
|
471
|
-
if (items[items.length - 1] instanceof GeneratorFunction) {
|
|
472
|
-
return function* (source) {
|
|
473
|
-
// @ts-ignore
|
|
474
|
-
let tail = source;
|
|
475
|
-
for (const activity of items) {
|
|
476
|
-
// @ts-ignore
|
|
477
|
-
tail = activity(tail);
|
|
478
|
-
}
|
|
479
|
-
yield* tail;
|
|
480
|
-
};
|
|
481
|
-
}
|
|
482
|
-
else {
|
|
483
|
-
return function (source) {
|
|
484
|
-
// @ts-ignore
|
|
485
|
-
let tail = source;
|
|
486
|
-
for (const activity of items) {
|
|
487
|
-
// @ts-ignore
|
|
488
|
-
tail = activity(tail);
|
|
489
|
-
}
|
|
490
|
-
return tail;
|
|
491
|
-
};
|
|
492
|
-
}
|
|
493
|
-
}
|
|
494
|
-
function pipe(s_or_ia, ...items) {
|
|
495
|
-
return isSource(s_or_ia) ? chainGen(...items)(s_or_ia) : chainGen(s_or_ia, ...items);
|
|
496
|
-
}
|
|
497
|
-
// Maintain backward compatibility
|
|
469
|
+
const GeneratorFunction = (function* () { }).constructor;
|
|
470
|
+
function chainGen(...items) {
|
|
471
|
+
if (items[items.length - 1] instanceof GeneratorFunction) {
|
|
472
|
+
return function* (source) {
|
|
473
|
+
// @ts-ignore
|
|
474
|
+
let tail = source;
|
|
475
|
+
for (const activity of items) {
|
|
476
|
+
// @ts-ignore
|
|
477
|
+
tail = activity(tail);
|
|
478
|
+
}
|
|
479
|
+
yield* tail;
|
|
480
|
+
};
|
|
481
|
+
}
|
|
482
|
+
else {
|
|
483
|
+
return function (source) {
|
|
484
|
+
// @ts-ignore
|
|
485
|
+
let tail = source;
|
|
486
|
+
for (const activity of items) {
|
|
487
|
+
// @ts-ignore
|
|
488
|
+
tail = activity(tail);
|
|
489
|
+
}
|
|
490
|
+
return tail;
|
|
491
|
+
};
|
|
492
|
+
}
|
|
493
|
+
}
|
|
494
|
+
function pipe(s_or_ia, ...items) {
|
|
495
|
+
return isSource(s_or_ia) ? chainGen(...items)(s_or_ia) : chainGen(s_or_ia, ...items);
|
|
496
|
+
}
|
|
497
|
+
// Maintain backward compatibility
|
|
498
498
|
const chain = pipe;
|
|
499
499
|
|
|
500
500
|
exports.Accessor = Accessor;
|
|
@@ -529,5 +529,5 @@
|
|
|
529
529
|
|
|
530
530
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
531
531
|
|
|
532
|
-
}))
|
|
532
|
+
}));
|
|
533
533
|
//# sourceMappingURL=index.js.map
|