@hpcc-js/dataflow 9.1.0 → 9.3.0

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