@hpcc-js/dataflow 8.1.1 → 8.1.2

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 (166) hide show
  1. package/LICENSE +43 -43
  2. package/README.md +530 -530
  3. package/dist/index.js +443 -443
  4. package/dist/index.js.map +1 -1
  5. package/dist/index.min.js.map +1 -1
  6. package/lib-es6/__package__.js +3 -3
  7. package/lib-es6/__package__.js.map +1 -1
  8. package/lib-es6/__tests__/chain.js +48 -48
  9. package/lib-es6/__tests__/concat.js +16 -16
  10. package/lib-es6/__tests__/count.js +18 -18
  11. package/lib-es6/__tests__/data.js +55 -55
  12. package/lib-es6/__tests__/deviation.js +12 -12
  13. package/lib-es6/__tests__/distribution.js +18 -18
  14. package/lib-es6/__tests__/each.js +11 -11
  15. package/lib-es6/__tests__/entries.js +12 -12
  16. package/lib-es6/__tests__/extent.js +18 -18
  17. package/lib-es6/__tests__/filter.js +13 -13
  18. package/lib-es6/__tests__/first.js +13 -13
  19. package/lib-es6/__tests__/generate.js +7 -7
  20. package/lib-es6/__tests__/group.js +17 -17
  21. package/lib-es6/__tests__/histogram.js +41 -41
  22. package/lib-es6/__tests__/map.js +13 -13
  23. package/lib-es6/__tests__/max.js +29 -29
  24. package/lib-es6/__tests__/mean.js +9 -9
  25. package/lib-es6/__tests__/median.js +12 -12
  26. package/lib-es6/__tests__/min.js +29 -29
  27. package/lib-es6/__tests__/quartile.js +11 -11
  28. package/lib-es6/__tests__/readme.js +95 -95
  29. package/lib-es6/__tests__/readme.js.map +1 -1
  30. package/lib-es6/__tests__/reduce.js +14 -14
  31. package/lib-es6/__tests__/skip.js +13 -13
  32. package/lib-es6/__tests__/sort.js +18 -18
  33. package/lib-es6/__tests__/variance.js +12 -12
  34. package/lib-es6/activities/activity.js +3 -3
  35. package/lib-es6/activities/concat.js +9 -9
  36. package/lib-es6/activities/each.js +13 -13
  37. package/lib-es6/activities/entries.js +12 -12
  38. package/lib-es6/activities/filter.js +14 -14
  39. package/lib-es6/activities/first.js +17 -17
  40. package/lib-es6/activities/group.js +20 -20
  41. package/lib-es6/activities/histogram.js +63 -63
  42. package/lib-es6/activities/map.js +12 -12
  43. package/lib-es6/activities/skip.js +16 -16
  44. package/lib-es6/activities/sort.js +9 -9
  45. package/lib-es6/index.js +25 -25
  46. package/lib-es6/observers/count.js +12 -12
  47. package/lib-es6/observers/deviation.js +17 -17
  48. package/lib-es6/observers/distribution.js +35 -35
  49. package/lib-es6/observers/extent.js +17 -17
  50. package/lib-es6/observers/max.js +18 -18
  51. package/lib-es6/observers/mean.js +20 -20
  52. package/lib-es6/observers/median.js +25 -25
  53. package/lib-es6/observers/min.js +18 -18
  54. package/lib-es6/observers/observer.js +34 -34
  55. package/lib-es6/observers/quartile.js +37 -37
  56. package/lib-es6/observers/reduce.js +17 -17
  57. package/lib-es6/observers/variance.js +22 -22
  58. package/lib-es6/utils/generate.js +6 -6
  59. package/lib-es6/utils/pipe.js +31 -31
  60. package/package.json +3 -3
  61. package/src/__package__.ts +3 -3
  62. package/src/__tests__/chain.ts +85 -85
  63. package/src/__tests__/concat.ts +18 -18
  64. package/src/__tests__/count.ts +25 -25
  65. package/src/__tests__/data.ts +64 -64
  66. package/src/__tests__/deviation.ts +14 -14
  67. package/src/__tests__/distribution.ts +21 -21
  68. package/src/__tests__/each.ts +13 -13
  69. package/src/__tests__/entries.ts +14 -14
  70. package/src/__tests__/extent.ts +25 -25
  71. package/src/__tests__/filter.ts +16 -16
  72. package/src/__tests__/first.ts +15 -15
  73. package/src/__tests__/generate.ts +9 -9
  74. package/src/__tests__/group.ts +19 -19
  75. package/src/__tests__/histogram.ts +47 -47
  76. package/src/__tests__/map.ts +16 -16
  77. package/src/__tests__/max.ts +42 -42
  78. package/src/__tests__/mean.ts +11 -11
  79. package/src/__tests__/median.ts +14 -14
  80. package/src/__tests__/min.ts +42 -42
  81. package/src/__tests__/quartile.ts +14 -14
  82. package/src/__tests__/readme.ts +113 -113
  83. package/src/__tests__/reduce.ts +17 -17
  84. package/src/__tests__/skip.ts +15 -15
  85. package/src/__tests__/sort.ts +21 -21
  86. package/src/__tests__/variance.ts +14 -14
  87. package/src/activities/activity.ts +8 -8
  88. package/src/activities/concat.ts +14 -14
  89. package/src/activities/each.ts +19 -19
  90. package/src/activities/entries.ts +17 -17
  91. package/src/activities/filter.ts +20 -20
  92. package/src/activities/first.ts +20 -20
  93. package/src/activities/group.ts +27 -27
  94. package/src/activities/histogram.ts +78 -78
  95. package/src/activities/map.ts +18 -18
  96. package/src/activities/skip.ts +19 -19
  97. package/src/activities/sort.ts +16 -16
  98. package/src/index.ts +25 -25
  99. package/src/observers/count.ts +15 -15
  100. package/src/observers/deviation.ts +24 -24
  101. package/src/observers/distribution.ts +51 -51
  102. package/src/observers/extent.ts +24 -24
  103. package/src/observers/max.ts +24 -24
  104. package/src/observers/mean.ts +26 -26
  105. package/src/observers/median.ts +30 -30
  106. package/src/observers/min.ts +24 -24
  107. package/src/observers/observer.ts +52 -52
  108. package/src/observers/quartile.ts +43 -43
  109. package/src/observers/reduce.ts +22 -22
  110. package/src/observers/variance.ts +29 -29
  111. package/src/utils/generate.ts +6 -6
  112. package/src/utils/pipe.ts +74 -74
  113. package/types/__package__.d.ts +3 -3
  114. package/types/__package__.d.ts.map +1 -1
  115. package/types/__tests__/chain.d.ts +1 -1
  116. package/types/__tests__/concat.d.ts +1 -1
  117. package/types/__tests__/count.d.ts +1 -1
  118. package/types/__tests__/data.d.ts +61 -61
  119. package/types/__tests__/deviation.d.ts +1 -1
  120. package/types/__tests__/distribution.d.ts +1 -1
  121. package/types/__tests__/each.d.ts +1 -1
  122. package/types/__tests__/entries.d.ts +1 -1
  123. package/types/__tests__/extent.d.ts +1 -1
  124. package/types/__tests__/filter.d.ts +1 -1
  125. package/types/__tests__/first.d.ts +1 -1
  126. package/types/__tests__/generate.d.ts +1 -1
  127. package/types/__tests__/group.d.ts +1 -1
  128. package/types/__tests__/histogram.d.ts +1 -1
  129. package/types/__tests__/map.d.ts +1 -1
  130. package/types/__tests__/max.d.ts +1 -1
  131. package/types/__tests__/mean.d.ts +1 -1
  132. package/types/__tests__/median.d.ts +1 -1
  133. package/types/__tests__/min.d.ts +1 -1
  134. package/types/__tests__/quartile.d.ts +1 -1
  135. package/types/__tests__/readme.d.ts +1 -1
  136. package/types/__tests__/reduce.d.ts +1 -1
  137. package/types/__tests__/skip.d.ts +1 -1
  138. package/types/__tests__/sort.d.ts +1 -1
  139. package/types/__tests__/variance.d.ts +1 -1
  140. package/types/activities/activity.d.ts +5 -5
  141. package/types/activities/concat.d.ts +3 -3
  142. package/types/activities/each.d.ts +4 -4
  143. package/types/activities/entries.d.ts +3 -3
  144. package/types/activities/filter.d.ts +4 -4
  145. package/types/activities/first.d.ts +3 -3
  146. package/types/activities/group.d.ts +8 -8
  147. package/types/activities/histogram.d.ts +17 -17
  148. package/types/activities/map.d.ts +4 -4
  149. package/types/activities/skip.d.ts +3 -3
  150. package/types/activities/sort.d.ts +4 -4
  151. package/types/index.d.ts +25 -25
  152. package/types/observers/count.d.ts +2 -2
  153. package/types/observers/deviation.d.ts +4 -4
  154. package/types/observers/distribution.d.ts +12 -12
  155. package/types/observers/extent.d.ts +4 -4
  156. package/types/observers/max.d.ts +4 -4
  157. package/types/observers/mean.d.ts +4 -4
  158. package/types/observers/median.d.ts +4 -4
  159. package/types/observers/min.d.ts +4 -4
  160. package/types/observers/observer.d.ts +13 -13
  161. package/types/observers/quartile.d.ts +5 -5
  162. package/types/observers/reduce.d.ts +3 -3
  163. package/types/observers/variance.d.ts +4 -4
  164. package/types/utils/generate.d.ts +1 -1
  165. package/types/utils/pipe.d.ts +41 -41
  166. package/types-3.4/__package__.d.ts +2 -2
@@ -1,17 +1,17 @@
1
- import { IterableActivity, Source } from "./activity";
2
-
3
- // Array.entries
4
- function entriesGen<T = any>(): IterableActivity<T, [number, T]> {
5
- return function* (source: Source<T>) {
6
- let i = -1;
7
- for (const item of source) {
8
- yield [++i, item];
9
- }
10
- };
11
- }
12
-
13
- export function entries<T = any>(): IterableActivity<T, [number, T]>;
14
- export function entries<T>(source: Source<T>): IterableIterator<[number, T]>;
15
- export function entries<T>(source?: Source<T>): IterableActivity<T, [number, T]> | IterableIterator<[number, T]> {
16
- return source ? entriesGen<T>()(source) : entriesGen<T>();
17
- }
1
+ import { IterableActivity, Source } from "./activity";
2
+
3
+ // Array.entries
4
+ function entriesGen<T = any>(): IterableActivity<T, [number, T]> {
5
+ return function* (source: Source<T>) {
6
+ let i = -1;
7
+ for (const item of source) {
8
+ yield [++i, item];
9
+ }
10
+ };
11
+ }
12
+
13
+ export function entries<T = any>(): IterableActivity<T, [number, T]>;
14
+ export function entries<T>(source: Source<T>): IterableIterator<[number, T]>;
15
+ export function entries<T>(source?: Source<T>): IterableActivity<T, [number, T]> | IterableIterator<[number, T]> {
16
+ return source ? entriesGen<T>()(source) : entriesGen<T>();
17
+ }
@@ -1,20 +1,20 @@
1
- import { IterableActivity, Source, isSource } from "./activity";
2
-
3
- export type FilterCallback<T> = (value: T, index: number) => boolean;
4
-
5
- function filterGen<T = any>(callbackFn: FilterCallback<T>): IterableActivity<T> {
6
- return function* (source: Source<T>) {
7
- let i = -1;
8
- for (const item of source) {
9
- if (callbackFn(item, ++i)) {
10
- yield item;
11
- }
12
- }
13
- };
14
- }
15
-
16
- export function filter<T = any>(callbackFn: FilterCallback<T>): IterableActivity<T>;
17
- export function filter<T>(source: Source<T>, callbackFn: FilterCallback<T>): IterableIterator<T>;
18
- export function filter<T>(s_or_cb: Source<T> | FilterCallback<T>, callbackFn?: FilterCallback<T>): IterableActivity<T> | IterableIterator<T> {
19
- return isSource(s_or_cb) ? filterGen(callbackFn!)(s_or_cb) : filterGen(s_or_cb);
20
- }
1
+ import { IterableActivity, Source, isSource } from "./activity";
2
+
3
+ export type FilterCallback<T> = (value: T, index: number) => boolean;
4
+
5
+ function filterGen<T = any>(callbackFn: FilterCallback<T>): IterableActivity<T> {
6
+ return function* (source: Source<T>) {
7
+ let i = -1;
8
+ for (const item of source) {
9
+ if (callbackFn(item, ++i)) {
10
+ yield item;
11
+ }
12
+ }
13
+ };
14
+ }
15
+
16
+ export function filter<T = any>(callbackFn: FilterCallback<T>): IterableActivity<T>;
17
+ export function filter<T>(source: Source<T>, callbackFn: FilterCallback<T>): IterableIterator<T>;
18
+ export function filter<T>(s_or_cb: Source<T> | FilterCallback<T>, callbackFn?: FilterCallback<T>): IterableActivity<T> | IterableIterator<T> {
19
+ return isSource(s_or_cb) ? filterGen(callbackFn!)(s_or_cb) : filterGen(s_or_cb);
20
+ }
@@ -1,20 +1,20 @@
1
- import { IterableActivity, isSource, Source } from "./activity";
2
-
3
- function firstGen<T = any>(n: number): IterableActivity<T, T> {
4
- return function* (source: Source<T>) {
5
- let i = 0;
6
- for (const item of source) {
7
- yield item;
8
- if (++i >= n) {
9
- break;
10
- }
11
- }
12
- };
13
- }
14
-
15
- export function first<T = any>(n: number): IterableActivity<T, T>;
16
- export function first<T>(source: Source<T>, n: number): IterableIterator<T>;
17
- export function first<T = any>(s_or_n: Source<T> | number, n?: number): IterableActivity<T, T> | IterableIterator<T> {
18
- if (!isSource(s_or_n)) return firstGen<T>(s_or_n);
19
- return firstGen<T>(n!)(s_or_n);
20
- }
1
+ import { IterableActivity, isSource, Source } from "./activity";
2
+
3
+ function firstGen<T = any>(n: number): IterableActivity<T, T> {
4
+ return function* (source: Source<T>) {
5
+ let i = 0;
6
+ for (const item of source) {
7
+ yield item;
8
+ if (++i >= n) {
9
+ break;
10
+ }
11
+ }
12
+ };
13
+ }
14
+
15
+ export function first<T = any>(n: number): IterableActivity<T, T>;
16
+ export function first<T>(source: Source<T>, n: number): IterableIterator<T>;
17
+ export function first<T = any>(s_or_n: Source<T> | number, n?: number): IterableActivity<T, T> | IterableIterator<T> {
18
+ if (!isSource(s_or_n)) return firstGen<T>(s_or_n);
19
+ return firstGen<T>(n!)(s_or_n);
20
+ }
@@ -1,27 +1,27 @@
1
- import { IterableActivity, Source, isSource } from "./activity";
2
-
3
- export type GroupFn<T> = (row: T, index: number) => number | string;
4
- export type GroupRow<T> = { key: string, value: T[] };
5
-
6
- function groupGen<T = any>(groupFn: GroupFn<T>): IterableActivity<T, GroupRow<T>> {
7
- return function* (source: Source<T>) {
8
- let i = -1;
9
- const group: { [key: string]: T[] } = {};
10
- for (const row of source) {
11
- const key = groupFn(row, ++i);
12
- if (!group[key]) {
13
- group[key] = [];
14
- }
15
- group[key].push(row);
16
- }
17
- for (const key in group) {
18
- yield { key, value: group[key] };
19
- }
20
- };
21
- }
22
-
23
- export function group<T>(groupByFn: GroupFn<T>): IterableActivity<T, GroupRow<T>>;
24
- export function group<T>(source: Source<T>, groupByFn: GroupFn<T>): IterableIterator<GroupRow<T>>;
25
- export function group<T>(s_or_gbf: Source<T> | GroupFn<T>, groupByFn?: GroupFn<T>): IterableActivity<T, GroupRow<T>> | IterableIterator<GroupRow<T>> {
26
- return isSource(s_or_gbf) ? groupGen<T>(groupByFn!)(s_or_gbf) : groupGen<T>(s_or_gbf);
27
- }
1
+ import { IterableActivity, Source, isSource } from "./activity";
2
+
3
+ export type GroupFn<T> = (row: T, index: number) => number | string;
4
+ export type GroupRow<T> = { key: string, value: T[] };
5
+
6
+ function groupGen<T = any>(groupFn: GroupFn<T>): IterableActivity<T, GroupRow<T>> {
7
+ return function* (source: Source<T>) {
8
+ let i = -1;
9
+ const group: { [key: string]: T[] } = {};
10
+ for (const row of source) {
11
+ const key = groupFn(row, ++i);
12
+ if (!group[key]) {
13
+ group[key] = [];
14
+ }
15
+ group[key].push(row);
16
+ }
17
+ for (const key in group) {
18
+ yield { key, value: group[key] };
19
+ }
20
+ };
21
+ }
22
+
23
+ export function group<T>(groupByFn: GroupFn<T>): IterableActivity<T, GroupRow<T>>;
24
+ export function group<T>(source: Source<T>, groupByFn: GroupFn<T>): IterableIterator<GroupRow<T>>;
25
+ export function group<T>(s_or_gbf: Source<T> | GroupFn<T>, groupByFn?: GroupFn<T>): IterableActivity<T, GroupRow<T>> | IterableIterator<GroupRow<T>> {
26
+ return isSource(s_or_gbf) ? groupGen<T>(groupByFn!)(s_or_gbf) : groupGen<T>(s_or_gbf);
27
+ }
@@ -1,78 +1,78 @@
1
- import { IterableActivity, Source, isSource } from "./activity";
2
- import { extent } from "../observers/extent";
3
- import { scalar } from "../observers/observer";
4
-
5
- export type HistogramFn<T> = (row: T) => number;
6
- export type HistogramRow<T> = { from: number, to: number, value: T[] };
7
- export type OptionA = { buckets: number };
8
- export type OptionB = { min: number, range: number };
9
- export type Options = OptionA | OptionB;
10
-
11
- function isOptionA(_: Options): _ is OptionA {
12
- return (_ as OptionA).buckets !== undefined;
13
- }
14
-
15
- function histogramGen<T = any>(callbackFn: HistogramFn<T>, options: Options): IterableActivity<T, HistogramRow<T>> {
16
- return function* (_source: Source<T>) {
17
- let min: number;
18
- let bucketSize: number;
19
-
20
- let source;
21
- if (isOptionA(options)) {
22
- source = Array.isArray(_source) ? _source : [..._source];
23
- const minMax = scalar(extent(callbackFn))(source);
24
- if (minMax === undefined) {
25
- return undefined;
26
- }
27
- min = minMax[0];
28
- const max = minMax[1];
29
- const buckets = options.buckets;
30
- bucketSize = (max - min) / buckets;
31
- } else {
32
- source = _source;
33
- min = options.min;
34
- bucketSize = options.range;
35
- }
36
-
37
- const histogram: { [key: number]: T[] } = {};
38
-
39
- let maxBucketID = 0;
40
- for (const row of source) {
41
- const value = callbackFn(row);
42
- const bucketID = Math.floor((value - min) / bucketSize);
43
- if (maxBucketID < bucketID) {
44
- maxBucketID = bucketID;
45
- }
46
- if (histogram[bucketID] === undefined) {
47
- histogram[bucketID] = [];
48
- }
49
- histogram[bucketID].push(row);
50
- }
51
-
52
- const lastBucket = histogram[maxBucketID];
53
- const from = min + maxBucketID * bucketSize;
54
-
55
- for (let i = 0; i <= maxBucketID; ++i) {
56
- // If all items in the last bucket match the "to" of the previous bucket, put them in there...
57
- if (i === maxBucketID - 1 && lastBucket.every(row => from === callbackFn(row))) {
58
- yield {
59
- from: min + i * bucketSize,
60
- to: min + (i + 1) * bucketSize,
61
- value: [...(histogram[i] || []), ...lastBucket]
62
- };
63
- break;
64
- }
65
- yield {
66
- from: min + i * bucketSize,
67
- to: min + (i + 1) * bucketSize,
68
- value: histogram[i] || []
69
- };
70
- }
71
- };
72
- }
73
-
74
- export function histogram<T>(histogramByFn: HistogramFn<T>, options: Options): IterableActivity<T, HistogramRow<T>>;
75
- export function histogram<T>(source: Source<T>, histogramByFn: HistogramFn<T>, options: Options): IterableIterator<HistogramRow<T>>;
76
- export function histogram<T>(s_or_hf: Source<T> | HistogramFn<T>, hf_or_b: HistogramFn<T> | Options, options?: Options): IterableActivity<T, HistogramRow<T>> | IterableIterator<HistogramRow<T>> {
77
- return isSource(s_or_hf) ? histogramGen<T>(hf_or_b as HistogramFn<T>, options!)(s_or_hf) : histogramGen<T>(s_or_hf as HistogramFn<T>, hf_or_b as Options);
78
- }
1
+ import { IterableActivity, Source, isSource } from "./activity";
2
+ import { extent } from "../observers/extent";
3
+ import { scalar } from "../observers/observer";
4
+
5
+ export type HistogramFn<T> = (row: T) => number;
6
+ export type HistogramRow<T> = { from: number, to: number, value: T[] };
7
+ export type OptionA = { buckets: number };
8
+ export type OptionB = { min: number, range: number };
9
+ export type Options = OptionA | OptionB;
10
+
11
+ function isOptionA(_: Options): _ is OptionA {
12
+ return (_ as OptionA).buckets !== undefined;
13
+ }
14
+
15
+ function histogramGen<T = any>(callbackFn: HistogramFn<T>, options: Options): IterableActivity<T, HistogramRow<T>> {
16
+ return function* (_source: Source<T>) {
17
+ let min: number;
18
+ let bucketSize: number;
19
+
20
+ let source;
21
+ if (isOptionA(options)) {
22
+ source = Array.isArray(_source) ? _source : [..._source];
23
+ const minMax = scalar(extent(callbackFn))(source);
24
+ if (minMax === undefined) {
25
+ return undefined;
26
+ }
27
+ min = minMax[0];
28
+ const max = minMax[1];
29
+ const buckets = options.buckets;
30
+ bucketSize = (max - min) / buckets;
31
+ } else {
32
+ source = _source;
33
+ min = options.min;
34
+ bucketSize = options.range;
35
+ }
36
+
37
+ const histogram: { [key: number]: T[] } = {};
38
+
39
+ let maxBucketID = 0;
40
+ for (const row of source) {
41
+ const value = callbackFn(row);
42
+ const bucketID = Math.floor((value - min) / bucketSize);
43
+ if (maxBucketID < bucketID) {
44
+ maxBucketID = bucketID;
45
+ }
46
+ if (histogram[bucketID] === undefined) {
47
+ histogram[bucketID] = [];
48
+ }
49
+ histogram[bucketID].push(row);
50
+ }
51
+
52
+ const lastBucket = histogram[maxBucketID];
53
+ const from = min + maxBucketID * bucketSize;
54
+
55
+ for (let i = 0; i <= maxBucketID; ++i) {
56
+ // If all items in the last bucket match the "to" of the previous bucket, put them in there...
57
+ if (i === maxBucketID - 1 && lastBucket.every(row => from === callbackFn(row))) {
58
+ yield {
59
+ from: min + i * bucketSize,
60
+ to: min + (i + 1) * bucketSize,
61
+ value: [...(histogram[i] || []), ...lastBucket]
62
+ };
63
+ break;
64
+ }
65
+ yield {
66
+ from: min + i * bucketSize,
67
+ to: min + (i + 1) * bucketSize,
68
+ value: histogram[i] || []
69
+ };
70
+ }
71
+ };
72
+ }
73
+
74
+ export function histogram<T>(histogramByFn: HistogramFn<T>, options: Options): IterableActivity<T, HistogramRow<T>>;
75
+ export function histogram<T>(source: Source<T>, histogramByFn: HistogramFn<T>, options: Options): IterableIterator<HistogramRow<T>>;
76
+ export function histogram<T>(s_or_hf: Source<T> | HistogramFn<T>, hf_or_b: HistogramFn<T> | Options, options?: Options): IterableActivity<T, HistogramRow<T>> | IterableIterator<HistogramRow<T>> {
77
+ return isSource(s_or_hf) ? histogramGen<T>(hf_or_b as HistogramFn<T>, options!)(s_or_hf) : histogramGen<T>(s_or_hf as HistogramFn<T>, hf_or_b as Options);
78
+ }
@@ -1,18 +1,18 @@
1
- import { IterableActivity, Source, isSource } from "./activity";
2
-
3
- export type MapCallback<T, U> = (row: T, index: number) => U;
4
-
5
- function mapGen<T = any, U = any>(callbackFn: MapCallback<T, U>): IterableActivity<T, U> {
6
- return function* (source: Source<T>) {
7
- let i = -1;
8
- for (const item of source) {
9
- yield callbackFn(item, ++i);
10
- }
11
- };
12
- }
13
-
14
- export function map<T, U>(callbackFn: MapCallback<T, U>): IterableActivity<T, U>;
15
- export function map<T, U>(source: Source<T>, callbackFn: MapCallback<T, U>): IterableIterator<U>;
16
- export function map<T, U>(s_or_cb: Source<T> | MapCallback<T, U>, callbackFn?: MapCallback<T, U>): IterableActivity<T, U> | IterableIterator<U> {
17
- return isSource(s_or_cb) ? mapGen(callbackFn!)(s_or_cb) : mapGen(s_or_cb);
18
- }
1
+ import { IterableActivity, Source, isSource } from "./activity";
2
+
3
+ export type MapCallback<T, U> = (row: T, index: number) => U;
4
+
5
+ function mapGen<T = any, U = any>(callbackFn: MapCallback<T, U>): IterableActivity<T, U> {
6
+ return function* (source: Source<T>) {
7
+ let i = -1;
8
+ for (const item of source) {
9
+ yield callbackFn(item, ++i);
10
+ }
11
+ };
12
+ }
13
+
14
+ export function map<T, U>(callbackFn: MapCallback<T, U>): IterableActivity<T, U>;
15
+ export function map<T, U>(source: Source<T>, callbackFn: MapCallback<T, U>): IterableIterator<U>;
16
+ export function map<T, U>(s_or_cb: Source<T> | MapCallback<T, U>, callbackFn?: MapCallback<T, U>): IterableActivity<T, U> | IterableIterator<U> {
17
+ return isSource(s_or_cb) ? mapGen(callbackFn!)(s_or_cb) : mapGen(s_or_cb);
18
+ }
@@ -1,19 +1,19 @@
1
- import { IterableActivity, Source, isSource } from "./activity";
2
-
3
- function skipGen<T = any>(n: number): IterableActivity<T, T> {
4
- return function* (source: Source<T>) {
5
- let i = -1;
6
- for (const item of source) {
7
- if (++i >= n) {
8
- yield item;
9
- }
10
- }
11
- };
12
- }
13
-
14
- export function skip<T = any>(n: number): IterableActivity<T, T>;
15
- export function skip<T>(source: Source<T>, n: number): IterableIterator<T>;
16
- export function skip<T = any>(s_or_n: Source<T> | number, n?: number): IterableActivity<T, T> | IterableIterator<T> {
17
- if (!isSource(s_or_n)) return skipGen<T>(s_or_n);
18
- return skipGen<T>(n!)(s_or_n);
19
- }
1
+ import { IterableActivity, Source, isSource } from "./activity";
2
+
3
+ function skipGen<T = any>(n: number): IterableActivity<T, T> {
4
+ return function* (source: Source<T>) {
5
+ let i = -1;
6
+ for (const item of source) {
7
+ if (++i >= n) {
8
+ yield item;
9
+ }
10
+ }
11
+ };
12
+ }
13
+
14
+ export function skip<T = any>(n: number): IterableActivity<T, T>;
15
+ export function skip<T>(source: Source<T>, n: number): IterableIterator<T>;
16
+ export function skip<T = any>(s_or_n: Source<T> | number, n?: number): IterableActivity<T, T> | IterableIterator<T> {
17
+ if (!isSource(s_or_n)) return skipGen<T>(s_or_n);
18
+ return skipGen<T>(n!)(s_or_n);
19
+ }
@@ -1,16 +1,16 @@
1
- import { IterableActivity, Source, isSource } from "./activity";
2
-
3
- export type SortCallback<T> = (a: T, b: T) => number;
4
-
5
- function sortGen<T = any>(compareFn?: SortCallback<T>): IterableActivity<T> {
6
- return function* (source: Source<T>) {
7
- yield* (Array.isArray(source) ? source : [...source]).sort(compareFn);
8
- };
9
- }
10
-
11
- export function sort<T = any>(callbackFn: SortCallback<T>): IterableActivity<T>;
12
- export function sort<T = any>(source: Source<T>, callbackFn: SortCallback<T>): IterableIterator<T>;
13
- export function sort<T = any>(s_or_cb: Source<T> | SortCallback<T>, callbackFn?: SortCallback<T>): IterableActivity<T> | IterableIterator<T> {
14
- return isSource(s_or_cb) ? sortGen(callbackFn!)(s_or_cb) : sortGen(s_or_cb);
15
- }
16
-
1
+ import { IterableActivity, Source, isSource } from "./activity";
2
+
3
+ export type SortCallback<T> = (a: T, b: T) => number;
4
+
5
+ function sortGen<T = any>(compareFn?: SortCallback<T>): IterableActivity<T> {
6
+ return function* (source: Source<T>) {
7
+ yield* (Array.isArray(source) ? source : [...source]).sort(compareFn);
8
+ };
9
+ }
10
+
11
+ export function sort<T = any>(callbackFn: SortCallback<T>): IterableActivity<T>;
12
+ export function sort<T = any>(source: Source<T>, callbackFn: SortCallback<T>): IterableIterator<T>;
13
+ export function sort<T = any>(s_or_cb: Source<T> | SortCallback<T>, callbackFn?: SortCallback<T>): IterableActivity<T> | IterableIterator<T> {
14
+ return isSource(s_or_cb) ? sortGen(callbackFn!)(s_or_cb) : sortGen(s_or_cb);
15
+ }
16
+
package/src/index.ts CHANGED
@@ -1,25 +1,25 @@
1
- export * from "./activities/activity";
2
- export * from "./activities/concat";
3
- export * from "./activities/each";
4
- export * from "./activities/entries";
5
- export * from "./activities/filter";
6
- export * from "./activities/first";
7
- export * from "./activities/group";
8
- export * from "./activities/histogram";
9
- export * from "./activities/map";
10
- export * from "./activities/skip";
11
- export * from "./activities/sort";
12
- export * from "./observers/count";
13
- export * from "./observers/deviation";
14
- export * from "./observers/distribution";
15
- export * from "./observers/extent";
16
- export * from "./observers/observer";
17
- export * from "./observers/max";
18
- export * from "./observers/mean";
19
- export * from "./observers/median";
20
- export * from "./observers/min";
21
- export * from "./observers/quartile";
22
- export * from "./observers/reduce";
23
- export * from "./observers/variance";
24
- export * from "./utils/generate";
25
- export * from "./utils/pipe";
1
+ export * from "./activities/activity";
2
+ export * from "./activities/concat";
3
+ export * from "./activities/each";
4
+ export * from "./activities/entries";
5
+ export * from "./activities/filter";
6
+ export * from "./activities/first";
7
+ export * from "./activities/group";
8
+ export * from "./activities/histogram";
9
+ export * from "./activities/map";
10
+ export * from "./activities/skip";
11
+ export * from "./activities/sort";
12
+ export * from "./observers/count";
13
+ export * from "./observers/deviation";
14
+ export * from "./observers/distribution";
15
+ export * from "./observers/extent";
16
+ export * from "./observers/observer";
17
+ export * from "./observers/max";
18
+ export * from "./observers/mean";
19
+ export * from "./observers/median";
20
+ export * from "./observers/min";
21
+ export * from "./observers/quartile";
22
+ export * from "./observers/reduce";
23
+ export * from "./observers/variance";
24
+ export * from "./utils/generate";
25
+ export * from "./utils/pipe";
@@ -1,15 +1,15 @@
1
- import { Observer } from "./observer";
2
-
3
- export function count<T = any>(): Observer<T, number> {
4
- let count: number;
5
-
6
- return {
7
- observe: (value: T, idx: number) => {
8
- if (idx === 0) {
9
- count = 0;
10
- }
11
- ++count;
12
- },
13
- peek: () => count
14
- };
15
- }
1
+ import { Observer } from "./observer";
2
+
3
+ export function count<T = any>(): Observer<T, number> {
4
+ let count: number;
5
+
6
+ return {
7
+ observe: (value: T, idx: number) => {
8
+ if (idx === 0) {
9
+ count = 0;
10
+ }
11
+ ++count;
12
+ },
13
+ peek: () => count
14
+ };
15
+ }
@@ -1,24 +1,24 @@
1
- import { variance } from "./variance";
2
- import { AccessorT, Observer, Accessor } from "./observer";
3
-
4
- function _deviation(): Observer<number, number | undefined> {
5
- const v = variance();
6
-
7
- return {
8
- observe: (value: number, idx: number) => {
9
- v.observe(value, idx);
10
- },
11
- peek: () => {
12
- const variance = v.peek();
13
- return variance !== undefined ? Math.sqrt(variance) : variance;
14
- }
15
- };
16
- }
17
-
18
- export type DeviationAccessor<T> = AccessorT<T, number>;
19
-
20
- export function deviation(): Observer<number, number | undefined>;
21
- export function deviation<T = any>(callbackFn: DeviationAccessor<T>): Observer<T, number | undefined>;
22
- export function deviation<T = any>(callbackFn?: DeviationAccessor<T>): Observer<number, number | undefined> | Observer<T, number | undefined> {
23
- return callbackFn ? Accessor(_deviation, callbackFn) : _deviation();
24
- }
1
+ import { variance } from "./variance";
2
+ import { AccessorT, Observer, Accessor } from "./observer";
3
+
4
+ function _deviation(): Observer<number, number | undefined> {
5
+ const v = variance();
6
+
7
+ return {
8
+ observe: (value: number, idx: number) => {
9
+ v.observe(value, idx);
10
+ },
11
+ peek: () => {
12
+ const variance = v.peek();
13
+ return variance !== undefined ? Math.sqrt(variance) : variance;
14
+ }
15
+ };
16
+ }
17
+
18
+ export type DeviationAccessor<T> = AccessorT<T, number>;
19
+
20
+ export function deviation(): Observer<number, number | undefined>;
21
+ export function deviation<T = any>(callbackFn: DeviationAccessor<T>): Observer<T, number | undefined>;
22
+ export function deviation<T = any>(callbackFn?: DeviationAccessor<T>): Observer<number, number | undefined> | Observer<T, number | undefined> {
23
+ return callbackFn ? Accessor(_deviation, callbackFn) : _deviation();
24
+ }