@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.
Files changed (164) hide show
  1. package/LICENSE +43 -43
  2. package/README.md +530 -530
  3. package/dist/index.js +446 -446
  4. package/dist/index.js.map +1 -1
  5. package/dist/index.min.js +1 -1
  6. package/dist/index.min.js.map +1 -1
  7. package/lib-es6/__package__.js +3 -3
  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__/reduce.js +14 -14
  30. package/lib-es6/__tests__/skip.js +13 -13
  31. package/lib-es6/__tests__/sort.js +18 -18
  32. package/lib-es6/__tests__/variance.js +12 -12
  33. package/lib-es6/activities/activity.js +3 -3
  34. package/lib-es6/activities/concat.js +9 -9
  35. package/lib-es6/activities/each.js +13 -13
  36. package/lib-es6/activities/entries.js +12 -12
  37. package/lib-es6/activities/filter.js +14 -14
  38. package/lib-es6/activities/first.js +17 -17
  39. package/lib-es6/activities/group.js +20 -20
  40. package/lib-es6/activities/histogram.js +63 -63
  41. package/lib-es6/activities/map.js +12 -12
  42. package/lib-es6/activities/skip.js +16 -16
  43. package/lib-es6/activities/sort.js +9 -9
  44. package/lib-es6/index.js +25 -25
  45. package/lib-es6/observers/count.js +12 -12
  46. package/lib-es6/observers/deviation.js +17 -17
  47. package/lib-es6/observers/distribution.js +35 -35
  48. package/lib-es6/observers/extent.js +17 -17
  49. package/lib-es6/observers/max.js +18 -18
  50. package/lib-es6/observers/mean.js +20 -20
  51. package/lib-es6/observers/median.js +25 -25
  52. package/lib-es6/observers/min.js +18 -18
  53. package/lib-es6/observers/observer.js +34 -34
  54. package/lib-es6/observers/quartile.js +37 -37
  55. package/lib-es6/observers/reduce.js +17 -17
  56. package/lib-es6/observers/variance.js +22 -22
  57. package/lib-es6/utils/generate.js +6 -6
  58. package/lib-es6/utils/pipe.js +31 -31
  59. package/package.json +6 -24
  60. package/src/__package__.ts +3 -3
  61. package/src/__tests__/chain.ts +85 -85
  62. package/src/__tests__/concat.ts +18 -18
  63. package/src/__tests__/count.ts +25 -25
  64. package/src/__tests__/data.ts +64 -64
  65. package/src/__tests__/deviation.ts +14 -14
  66. package/src/__tests__/distribution.ts +21 -21
  67. package/src/__tests__/each.ts +13 -13
  68. package/src/__tests__/entries.ts +14 -14
  69. package/src/__tests__/extent.ts +25 -25
  70. package/src/__tests__/filter.ts +16 -16
  71. package/src/__tests__/first.ts +15 -15
  72. package/src/__tests__/generate.ts +9 -9
  73. package/src/__tests__/group.ts +19 -19
  74. package/src/__tests__/histogram.ts +47 -47
  75. package/src/__tests__/map.ts +16 -16
  76. package/src/__tests__/max.ts +42 -42
  77. package/src/__tests__/mean.ts +11 -11
  78. package/src/__tests__/median.ts +14 -14
  79. package/src/__tests__/min.ts +42 -42
  80. package/src/__tests__/quartile.ts +14 -14
  81. package/src/__tests__/readme.ts +113 -113
  82. package/src/__tests__/reduce.ts +17 -17
  83. package/src/__tests__/skip.ts +15 -15
  84. package/src/__tests__/sort.ts +21 -21
  85. package/src/__tests__/variance.ts +14 -14
  86. package/src/activities/activity.ts +8 -8
  87. package/src/activities/concat.ts +14 -14
  88. package/src/activities/each.ts +19 -19
  89. package/src/activities/entries.ts +17 -17
  90. package/src/activities/filter.ts +20 -20
  91. package/src/activities/first.ts +20 -20
  92. package/src/activities/group.ts +27 -27
  93. package/src/activities/histogram.ts +78 -78
  94. package/src/activities/map.ts +18 -18
  95. package/src/activities/skip.ts +19 -19
  96. package/src/activities/sort.ts +16 -16
  97. package/src/index.ts +25 -25
  98. package/src/observers/count.ts +15 -15
  99. package/src/observers/deviation.ts +24 -24
  100. package/src/observers/distribution.ts +51 -51
  101. package/src/observers/extent.ts +24 -24
  102. package/src/observers/max.ts +24 -24
  103. package/src/observers/mean.ts +26 -26
  104. package/src/observers/median.ts +30 -30
  105. package/src/observers/min.ts +24 -24
  106. package/src/observers/observer.ts +52 -52
  107. package/src/observers/quartile.ts +43 -43
  108. package/src/observers/reduce.ts +22 -22
  109. package/src/observers/variance.ts +29 -29
  110. package/src/utils/generate.ts +6 -6
  111. package/src/utils/pipe.ts +74 -74
  112. package/types/__package__.d.ts +3 -3
  113. package/types/__tests__/chain.d.ts +1 -1
  114. package/types/__tests__/concat.d.ts +1 -1
  115. package/types/__tests__/count.d.ts +1 -1
  116. package/types/__tests__/data.d.ts +61 -61
  117. package/types/__tests__/deviation.d.ts +1 -1
  118. package/types/__tests__/distribution.d.ts +1 -1
  119. package/types/__tests__/each.d.ts +1 -1
  120. package/types/__tests__/entries.d.ts +1 -1
  121. package/types/__tests__/extent.d.ts +1 -1
  122. package/types/__tests__/filter.d.ts +1 -1
  123. package/types/__tests__/first.d.ts +1 -1
  124. package/types/__tests__/generate.d.ts +1 -1
  125. package/types/__tests__/group.d.ts +1 -1
  126. package/types/__tests__/histogram.d.ts +1 -1
  127. package/types/__tests__/map.d.ts +1 -1
  128. package/types/__tests__/max.d.ts +1 -1
  129. package/types/__tests__/mean.d.ts +1 -1
  130. package/types/__tests__/median.d.ts +1 -1
  131. package/types/__tests__/min.d.ts +1 -1
  132. package/types/__tests__/quartile.d.ts +1 -1
  133. package/types/__tests__/readme.d.ts +1 -1
  134. package/types/__tests__/reduce.d.ts +1 -1
  135. package/types/__tests__/skip.d.ts +1 -1
  136. package/types/__tests__/sort.d.ts +1 -1
  137. package/types/__tests__/variance.d.ts +1 -1
  138. package/types/activities/activity.d.ts +5 -5
  139. package/types/activities/concat.d.ts +3 -3
  140. package/types/activities/each.d.ts +4 -4
  141. package/types/activities/entries.d.ts +3 -3
  142. package/types/activities/filter.d.ts +4 -4
  143. package/types/activities/first.d.ts +3 -3
  144. package/types/activities/group.d.ts +8 -8
  145. package/types/activities/histogram.d.ts +17 -17
  146. package/types/activities/map.d.ts +4 -4
  147. package/types/activities/skip.d.ts +3 -3
  148. package/types/activities/sort.d.ts +4 -4
  149. package/types/index.d.ts +25 -25
  150. package/types/observers/count.d.ts +2 -2
  151. package/types/observers/deviation.d.ts +4 -4
  152. package/types/observers/distribution.d.ts +12 -12
  153. package/types/observers/extent.d.ts +4 -4
  154. package/types/observers/max.d.ts +4 -4
  155. package/types/observers/mean.d.ts +4 -4
  156. package/types/observers/median.d.ts +4 -4
  157. package/types/observers/min.d.ts +4 -4
  158. package/types/observers/observer.d.ts +13 -13
  159. package/types/observers/quartile.d.ts +5 -5
  160. package/types/observers/reduce.d.ts +3 -3
  161. package/types/observers/variance.d.ts +4 -4
  162. package/types/utils/generate.d.ts +1 -1
  163. package/types/utils/pipe.d.ts +41 -41
  164. package/types-3.4/__package__.d.ts +2 -2
@@ -1,14 +1,14 @@
1
- import { expect } from "chai";
2
- import { map } from "../index";
3
- import { population } from "./data";
4
- const testMap = row => (Object.assign({}, row.address));
5
- const expected = population.map(testMap);
6
- describe("map", () => {
7
- it("generator", () => {
8
- expect([...map(testMap)(population)]).to.deep.equal(expected);
9
- });
10
- it("scalarActivity", () => {
11
- expect([...map(population, testMap)]).to.deep.equal(expected);
12
- });
13
- });
1
+ import { expect } from "chai";
2
+ import { map } from "../index";
3
+ import { population } from "./data";
4
+ const testMap = row => (Object.assign({}, row.address));
5
+ const expected = population.map(testMap);
6
+ describe("map", () => {
7
+ it("generator", () => {
8
+ expect([...map(testMap)(population)]).to.deep.equal(expected);
9
+ });
10
+ it("scalarActivity", () => {
11
+ expect([...map(population, testMap)]).to.deep.equal(expected);
12
+ });
13
+ });
14
14
  //# sourceMappingURL=map.js.map
@@ -1,30 +1,30 @@
1
- import { expect } from "chai";
2
- import { pipe, filter, max, scalar, sensor } from "../index";
3
- import { population } from "./data";
4
- describe("max", () => {
5
- it("NumberArray", () => {
6
- const s1 = max();
7
- const s2 = max();
8
- const p1 = pipe(sensor(s1), filter(r => r < 3), sensor(s2));
9
- const data = [...p1([1, 2, 3, 4, 5, 0])];
10
- expect(data.length).to.equal(3);
11
- expect(s1.peek()).to.equal(5);
12
- expect(s2.peek()).to.equal(2);
13
- });
14
- it("Population", () => {
15
- const s1 = max(r => r.age);
16
- const s2 = max(r => r.age);
17
- const p1 = pipe(sensor(s1), filter(r => r.age < 30), sensor(s2));
18
- const data = [...p1(population)];
19
- expect(data.length).to.equal(286);
20
- expect(s1.peek()).to.equal(66);
21
- expect(s2.peek()).to.equal(29);
22
- });
23
- it("scalarActivity", () => {
24
- const s1 = scalar(max());
25
- expect(s1([1, 2, 3, 4, 5, 0])).to.equal(5);
26
- const s2 = scalar(max(r => r.age));
27
- expect(s2(population)).to.equal(66);
28
- });
29
- });
1
+ import { expect } from "chai";
2
+ import { pipe, filter, max, scalar, sensor } from "../index";
3
+ import { population } from "./data";
4
+ describe("max", () => {
5
+ it("NumberArray", () => {
6
+ const s1 = max();
7
+ const s2 = max();
8
+ const p1 = pipe(sensor(s1), filter(r => r < 3), sensor(s2));
9
+ const data = [...p1([1, 2, 3, 4, 5, 0])];
10
+ expect(data.length).to.equal(3);
11
+ expect(s1.peek()).to.equal(5);
12
+ expect(s2.peek()).to.equal(2);
13
+ });
14
+ it("Population", () => {
15
+ const s1 = max(r => r.age);
16
+ const s2 = max(r => r.age);
17
+ const p1 = pipe(sensor(s1), filter(r => r.age < 30), sensor(s2));
18
+ const data = [...p1(population)];
19
+ expect(data.length).to.equal(286);
20
+ expect(s1.peek()).to.equal(66);
21
+ expect(s2.peek()).to.equal(29);
22
+ });
23
+ it("scalarActivity", () => {
24
+ const s1 = scalar(max());
25
+ expect(s1([1, 2, 3, 4, 5, 0])).to.equal(5);
26
+ const s2 = scalar(max(r => r.age));
27
+ expect(s2(population)).to.equal(66);
28
+ });
29
+ });
30
30
  //# sourceMappingURL=max.js.map
@@ -1,10 +1,10 @@
1
- import { expect } from "chai";
2
- import { mean, scalar } from "../index";
3
- describe("mean", () => {
4
- it("scalarActivity", () => {
5
- const a1 = scalar(mean());
6
- expect(a1([5, -6, 1, 2, -2])).to.equal(0);
7
- expect(a1([9])).to.deep.equal(9);
8
- });
9
- });
1
+ import { expect } from "chai";
2
+ import { mean, scalar } from "../index";
3
+ describe("mean", () => {
4
+ it("scalarActivity", () => {
5
+ const a1 = scalar(mean());
6
+ expect(a1([5, -6, 1, 2, -2])).to.equal(0);
7
+ expect(a1([9])).to.deep.equal(9);
8
+ });
9
+ });
10
10
  //# sourceMappingURL=mean.js.map
@@ -1,13 +1,13 @@
1
- import { expect } from "chai";
2
- import { median, scalar } from "../index";
3
- describe("median", () => {
4
- it("scalarActivity", () => {
5
- const calcMedian = scalar(median());
6
- expect(calcMedian([-6, -2, 1, 2, 5])).to.equal(1);
7
- expect(calcMedian([5, -6, 1, 2, -2])).to.equal(1);
8
- expect(calcMedian([-6, -2, 1, 2, 5, 6])).to.equal(1.5);
9
- expect(calcMedian([5, -6, 1, 2, -2, 6])).to.equal(1.5);
10
- expect(calcMedian([9])).to.deep.equal(9);
11
- });
12
- });
1
+ import { expect } from "chai";
2
+ import { median, scalar } from "../index";
3
+ describe("median", () => {
4
+ it("scalarActivity", () => {
5
+ const calcMedian = scalar(median());
6
+ expect(calcMedian([-6, -2, 1, 2, 5])).to.equal(1);
7
+ expect(calcMedian([5, -6, 1, 2, -2])).to.equal(1);
8
+ expect(calcMedian([-6, -2, 1, 2, 5, 6])).to.equal(1.5);
9
+ expect(calcMedian([5, -6, 1, 2, -2, 6])).to.equal(1.5);
10
+ expect(calcMedian([9])).to.deep.equal(9);
11
+ });
12
+ });
13
13
  //# sourceMappingURL=median.js.map
@@ -1,30 +1,30 @@
1
- import { expect } from "chai";
2
- import { pipe, filter, min, scalar, sensor } from "../index";
3
- import { population } from "./data";
4
- describe("min", () => {
5
- it("NumberArray", () => {
6
- const s1 = min();
7
- const s2 = min();
8
- const p1 = pipe(sensor(s1), filter(r => r > 3), sensor(s2));
9
- const data = [...p1([1, 2, 3, 4, 5, 0])];
10
- expect(data.length).to.equal(2);
11
- expect(s1.peek()).to.equal(0);
12
- expect(s2.peek()).to.equal(4);
13
- });
14
- it("Population", () => {
15
- const s1 = min(r => r.age);
16
- const s2 = min(r => r.age);
17
- const p1 = pipe(sensor(s1), filter(r => r.age > 30), sensor(s2));
18
- const data = [...p1(population)];
19
- expect(data.length).to.equal(699);
20
- expect(s1.peek()).to.equal(16);
21
- expect(s2.peek()).to.equal(31);
22
- });
23
- it("scalarActivity", () => {
24
- const a1 = scalar(min());
25
- expect(a1([1, 2, 3, 4, 5, 0])).to.equal(0);
26
- const a2 = scalar(min(r => r.age));
27
- expect(a2(population)).to.equal(16);
28
- });
29
- });
1
+ import { expect } from "chai";
2
+ import { pipe, filter, min, scalar, sensor } from "../index";
3
+ import { population } from "./data";
4
+ describe("min", () => {
5
+ it("NumberArray", () => {
6
+ const s1 = min();
7
+ const s2 = min();
8
+ const p1 = pipe(sensor(s1), filter(r => r > 3), sensor(s2));
9
+ const data = [...p1([1, 2, 3, 4, 5, 0])];
10
+ expect(data.length).to.equal(2);
11
+ expect(s1.peek()).to.equal(0);
12
+ expect(s2.peek()).to.equal(4);
13
+ });
14
+ it("Population", () => {
15
+ const s1 = min(r => r.age);
16
+ const s2 = min(r => r.age);
17
+ const p1 = pipe(sensor(s1), filter(r => r.age > 30), sensor(s2));
18
+ const data = [...p1(population)];
19
+ expect(data.length).to.equal(699);
20
+ expect(s1.peek()).to.equal(16);
21
+ expect(s2.peek()).to.equal(31);
22
+ });
23
+ it("scalarActivity", () => {
24
+ const a1 = scalar(min());
25
+ expect(a1([1, 2, 3, 4, 5, 0])).to.equal(0);
26
+ const a2 = scalar(min(r => r.age));
27
+ expect(a2(population)).to.equal(16);
28
+ });
29
+ });
30
30
  //# sourceMappingURL=min.js.map
@@ -1,12 +1,12 @@
1
- import { expect } from "chai";
2
- import { quartile, scalar } from "../index";
3
- describe("quartile", () => {
4
- it("scalarActivity", () => {
5
- const calcQuartile = scalar(quartile());
6
- expect(calcQuartile([6, 7, 15, 36, 39, 40, 41, 42, 43, 47, 49])).to.deep.equal([6, 15, 40, 43, 49]);
7
- expect(calcQuartile([7, 15, 36, 39, 40, 41])).to.deep.equal([7, 15, 37.5, 40, 41]);
8
- expect(calcQuartile([1, 22, 133])).to.deep.equal([1, 1, 22, 133, 133]);
9
- expect(calcQuartile([2, 144, 33])).to.deep.equal([2, 2, 33, 144, 144]);
10
- });
11
- });
1
+ import { expect } from "chai";
2
+ import { quartile, scalar } from "../index";
3
+ describe("quartile", () => {
4
+ it("scalarActivity", () => {
5
+ const calcQuartile = scalar(quartile());
6
+ expect(calcQuartile([6, 7, 15, 36, 39, 40, 41, 42, 43, 47, 49])).to.deep.equal([6, 15, 40, 43, 49]);
7
+ expect(calcQuartile([7, 15, 36, 39, 40, 41])).to.deep.equal([7, 15, 37.5, 40, 41]);
8
+ expect(calcQuartile([1, 22, 133])).to.deep.equal([1, 1, 22, 133, 133]);
9
+ expect(calcQuartile([2, 144, 33])).to.deep.equal([2, 2, 33, 144, 144]);
10
+ });
11
+ });
12
12
  //# sourceMappingURL=quartile.js.map
@@ -1,96 +1,96 @@
1
- import { expect } from "chai";
2
- import { count, filter, first, generate, map, max, pipe, sensor } from "../index";
3
- describe("readme", () => {
4
- it("quick example", () => {
5
- const c1 = count();
6
- const c2 = count();
7
- const c3 = count();
8
- const m1 = max(row => row.value);
9
- const p1 = pipe(sensor(c1), // Keep running count of input
10
- filter(n => n <= 0.5), // Filter out numbers > 0.5
11
- sensor(c2), // Keep running count of filtered rows
12
- map((n, idx) => // Convert to JSON Object
13
- ({ index: idx, value: n })), filter(row => row.index % 2 === 0), // Filter even row indecies
14
- sensor(c3), // Keep running count of final rows
15
- sensor(m1), // Track largest value
16
- first(3) // Take first 3 rows
17
- );
18
- console.log(`Counts: ${c1.peek()}, ${c2.peek()}, ${c3.peek()}`);
19
- // [1] => Counts: undefined, undefined, undefined
20
- const outIterable = p1(generate(Math.random, 1000));
21
- console.log(`Counts: ${c1.peek()}, ${c2.peek()}, ${c3.peek()}`);
22
- // [2] => Counts: undefined, undefined, undefined
23
- console.log(JSON.stringify([...outIterable]));
24
- // [3] => [{"index":0,"value":0.19075931906641008},{"index":2,"value":0.4873469062925415},{"index":4,"value":0.4412516774100035}]
25
- console.log(`Counts: ${c1.peek()}, ${c2.peek()}, ${c3.peek()}, ${m1.peek()}`);
26
- // [4] => Counts: 6, 5, 3, 0.4873469062925415
27
- const outArray = [...p1([0.7, 0.5, 0.4, 0.8, 0.3, 1])];
28
- console.log(JSON.stringify(outArray));
29
- // [5] => [{"index":0,"value":0.5},{"index":2,"value":0.3}]
30
- console.log(`Counts: ${c1.peek()}, ${c2.peek()}, ${c3.peek()}, ${m1.peek()}`);
31
- // [6] => Counts: 6, 3, 2, 0.5
32
- expect(outArray.length).to.equal(2);
33
- for (const row of p1(generate(Math.random, 1000000))) {
34
- console.log(`${row.index}: ${c1.peek()}, ${c2.peek()}, ${c3.peek()}, ${m1.peek()}`);
35
- }
36
- });
37
- it("interesting example", () => {
38
- const c1 = count();
39
- const c2 = count();
40
- const c3 = count();
41
- const m1 = max(row => row.value);
42
- const p1 = pipe(sensor(c1), // Keep running count of input
43
- filter(n => n <= 0.5), // Filter out numbers > 0.5
44
- sensor(c2), // Keep running count of filtered rows
45
- map((n, idx) => // Convert to JSON Object
46
- ({ index: idx, value: n })), filter(row => row.index % 2 === 0), // Filter even row indecies
47
- sensor(c3), // Keep running count of final rows
48
- sensor(m1));
49
- for (const row of p1(generate(Math.random, 1000000))) {
50
- if (row.index % 100000 === 0) {
51
- console.log(`${row.index}: ${c1.peek()}, ${c2.peek()}, ${c3.peek()}, ${m1.peek()}`);
52
- }
53
- }
54
- });
55
- });
56
- /*
57
- const process3 = pipe(
58
- filter(n => n <= 0.5),
59
- map((n, idx) => ({ index: idx, value: n })),
60
- filter(row => row.index % 2 === 0),
61
- sort((l, r) => l.value - r.value),
62
- first(3)
63
- );
64
- console.log(...process3([]));
65
-
66
- // Iterable output
67
- pipe([0, 1, 2, 3, 4, 5, 6, 7, 8, 9],
68
- filter(n => n <= 5),
69
- map((n, idx) => ({ index: idx, value: n })),
70
- filter(row => row.index % 2 === 0),
71
- sort((l, r) => l.value - r.value),
72
- first(3)
73
- ); // => { index: 0, value: 0 }, { index: 2, value: 2 }, { index: 4, value: 4 }
74
-
75
- const process = pipe(
76
- filter(n => n <= 5),
77
- map((n, idx) => ({ index: idx, value: n })),
78
- filter(row => row.index % 2 === 0),
79
- sort((l, r) => l.value - r.value),
80
- first(3)
81
- );
82
- console.log([...process([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])]); // => { index: 0, value: 0 }, { index: 2, value: 2 }, { index: 4, value: 4 }
83
-
84
- // Scalar output
85
- pipe([0, 1, 2, 3, 4, 5, 6, 7, 8, 9],
86
- process,
87
- scalar(max(row => row.value))
88
- ); // => 4
89
-
90
- const process_2 = pipe(
91
- process,
92
- scalar(min(row => row.value))
93
- );
94
- console.log(process_2([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])); // => 0
95
- */
1
+ import { expect } from "chai";
2
+ import { count, filter, first, generate, map, max, pipe, sensor } from "../index";
3
+ describe("readme", () => {
4
+ it("quick example", () => {
5
+ const c1 = count();
6
+ const c2 = count();
7
+ const c3 = count();
8
+ const m1 = max(row => row.value);
9
+ const p1 = pipe(sensor(c1), // Keep running count of input
10
+ filter(n => n <= 0.5), // Filter out numbers > 0.5
11
+ sensor(c2), // Keep running count of filtered rows
12
+ map((n, idx) => // Convert to JSON Object
13
+ ({ index: idx, value: n })), filter(row => row.index % 2 === 0), // Filter even row indecies
14
+ sensor(c3), // Keep running count of final rows
15
+ sensor(m1), // Track largest value
16
+ first(3) // Take first 3 rows
17
+ );
18
+ console.log(`Counts: ${c1.peek()}, ${c2.peek()}, ${c3.peek()}`);
19
+ // [1] => Counts: undefined, undefined, undefined
20
+ const outIterable = p1(generate(Math.random, 1000));
21
+ console.log(`Counts: ${c1.peek()}, ${c2.peek()}, ${c3.peek()}`);
22
+ // [2] => Counts: undefined, undefined, undefined
23
+ console.log(JSON.stringify([...outIterable]));
24
+ // [3] => [{"index":0,"value":0.19075931906641008},{"index":2,"value":0.4873469062925415},{"index":4,"value":0.4412516774100035}]
25
+ console.log(`Counts: ${c1.peek()}, ${c2.peek()}, ${c3.peek()}, ${m1.peek()}`);
26
+ // [4] => Counts: 6, 5, 3, 0.4873469062925415
27
+ const outArray = [...p1([0.7, 0.5, 0.4, 0.8, 0.3, 1])];
28
+ console.log(JSON.stringify(outArray));
29
+ // [5] => [{"index":0,"value":0.5},{"index":2,"value":0.3}]
30
+ console.log(`Counts: ${c1.peek()}, ${c2.peek()}, ${c3.peek()}, ${m1.peek()}`);
31
+ // [6] => Counts: 6, 3, 2, 0.5
32
+ expect(outArray.length).to.equal(2);
33
+ for (const row of p1(generate(Math.random, 1000000))) {
34
+ console.log(`${row.index}: ${c1.peek()}, ${c2.peek()}, ${c3.peek()}, ${m1.peek()}`);
35
+ }
36
+ });
37
+ it("interesting example", () => {
38
+ const c1 = count();
39
+ const c2 = count();
40
+ const c3 = count();
41
+ const m1 = max(row => row.value);
42
+ const p1 = pipe(sensor(c1), // Keep running count of input
43
+ filter(n => n <= 0.5), // Filter out numbers > 0.5
44
+ sensor(c2), // Keep running count of filtered rows
45
+ map((n, idx) => // Convert to JSON Object
46
+ ({ index: idx, value: n })), filter(row => row.index % 2 === 0), // Filter even row indecies
47
+ sensor(c3), // Keep running count of final rows
48
+ sensor(m1));
49
+ for (const row of p1(generate(Math.random, 1000000))) {
50
+ if (row.index % 100000 === 0) {
51
+ console.log(`${row.index}: ${c1.peek()}, ${c2.peek()}, ${c3.peek()}, ${m1.peek()}`);
52
+ }
53
+ }
54
+ });
55
+ });
56
+ /*
57
+ const process3 = pipe(
58
+ filter(n => n <= 0.5),
59
+ map((n, idx) => ({ index: idx, value: n })),
60
+ filter(row => row.index % 2 === 0),
61
+ sort((l, r) => l.value - r.value),
62
+ first(3)
63
+ );
64
+ console.log(...process3([]));
65
+
66
+ // Iterable output
67
+ pipe([0, 1, 2, 3, 4, 5, 6, 7, 8, 9],
68
+ filter(n => n <= 5),
69
+ map((n, idx) => ({ index: idx, value: n })),
70
+ filter(row => row.index % 2 === 0),
71
+ sort((l, r) => l.value - r.value),
72
+ first(3)
73
+ ); // => { index: 0, value: 0 }, { index: 2, value: 2 }, { index: 4, value: 4 }
74
+
75
+ const process = pipe(
76
+ filter(n => n <= 5),
77
+ map((n, idx) => ({ index: idx, value: n })),
78
+ filter(row => row.index % 2 === 0),
79
+ sort((l, r) => l.value - r.value),
80
+ first(3)
81
+ );
82
+ console.log([...process([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])]); // => { index: 0, value: 0 }, { index: 2, value: 2 }, { index: 4, value: 4 }
83
+
84
+ // Scalar output
85
+ pipe([0, 1, 2, 3, 4, 5, 6, 7, 8, 9],
86
+ process,
87
+ scalar(max(row => row.value))
88
+ ); // => 4
89
+
90
+ const process_2 = pipe(
91
+ process,
92
+ scalar(min(row => row.value))
93
+ );
94
+ console.log(process_2([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])); // => 0
95
+ */
96
96
  //# sourceMappingURL=readme.js.map
@@ -1,15 +1,15 @@
1
- import { expect } from "chai";
2
- import { reduce, scalar } from "../index";
3
- const data = [1, 2, 3, 4, 5];
4
- const reduceFunc = (prev, row) => prev + row;
5
- const expectedA = data.reduce(reduceFunc);
6
- const expectedB = data.reduce(reduceFunc, 10);
7
- describe("reduce", () => {
8
- it("scalarActivity", () => {
9
- const calcReduce = scalar(reduce(reduceFunc));
10
- const calcReduce2 = scalar(reduce(reduceFunc, 10));
11
- expect(calcReduce(data)).to.equal(expectedA);
12
- expect(calcReduce2(data)).to.equal(expectedB);
13
- });
14
- });
1
+ import { expect } from "chai";
2
+ import { reduce, scalar } from "../index";
3
+ const data = [1, 2, 3, 4, 5];
4
+ const reduceFunc = (prev, row) => prev + row;
5
+ const expectedA = data.reduce(reduceFunc);
6
+ const expectedB = data.reduce(reduceFunc, 10);
7
+ describe("reduce", () => {
8
+ it("scalarActivity", () => {
9
+ const calcReduce = scalar(reduce(reduceFunc));
10
+ const calcReduce2 = scalar(reduce(reduceFunc, 10));
11
+ expect(calcReduce(data)).to.equal(expectedA);
12
+ expect(calcReduce2(data)).to.equal(expectedB);
13
+ });
14
+ });
15
15
  //# sourceMappingURL=reduce.js.map
@@ -1,14 +1,14 @@
1
- import { expect } from "chai";
2
- import { skip } from "../index";
3
- describe("skip", () => {
4
- it("generator", () => {
5
- expect([...skip(2)([])]).to.deep.equal([]);
6
- expect([...skip(2)(["a", "b", "c"])]).to.deep.equal(["c"]);
7
- });
8
- it("scalarActivity", () => {
9
- expect([...skip([], 22)]).to.deep.equal([]);
10
- expect([...skip(["a", "b", "c"], 2)]).to.deep.equal(["c"]);
11
- expect([...skip(["a", "b", "c"], 22)]).to.deep.equal([]);
12
- });
13
- });
1
+ import { expect } from "chai";
2
+ import { skip } from "../index";
3
+ describe("skip", () => {
4
+ it("generator", () => {
5
+ expect([...skip(2)([])]).to.deep.equal([]);
6
+ expect([...skip(2)(["a", "b", "c"])]).to.deep.equal(["c"]);
7
+ });
8
+ it("scalarActivity", () => {
9
+ expect([...skip([], 22)]).to.deep.equal([]);
10
+ expect([...skip(["a", "b", "c"], 2)]).to.deep.equal(["c"]);
11
+ expect([...skip(["a", "b", "c"], 22)]).to.deep.equal([]);
12
+ });
13
+ });
14
14
  //# sourceMappingURL=skip.js.map
@@ -1,19 +1,19 @@
1
- import { expect } from "chai";
2
- import { sort } from "../index";
3
- import { population } from "./data";
4
- function sortFunc(l, r) {
5
- const retVal = l.lname.localeCompare(r.lname);
6
- if (retVal === 0)
7
- return l.fname.localeCompare(r.fname);
8
- return retVal;
9
- }
10
- const expected = [...population].sort(sortFunc);
11
- describe("sort", () => {
12
- it("generator", () => {
13
- expect([...sort(sortFunc)(population)]).to.deep.equal(expected);
14
- });
15
- it("scalarActivity", () => {
16
- expect([...sort(population, sortFunc)]).to.deep.equal(expected);
17
- });
18
- });
1
+ import { expect } from "chai";
2
+ import { sort } from "../index";
3
+ import { population } from "./data";
4
+ function sortFunc(l, r) {
5
+ const retVal = l.lname.localeCompare(r.lname);
6
+ if (retVal === 0)
7
+ return l.fname.localeCompare(r.fname);
8
+ return retVal;
9
+ }
10
+ const expected = [...population].sort(sortFunc);
11
+ describe("sort", () => {
12
+ it("generator", () => {
13
+ expect([...sort(sortFunc)(population)]).to.deep.equal(expected);
14
+ });
15
+ it("scalarActivity", () => {
16
+ expect([...sort(population, sortFunc)]).to.deep.equal(expected);
17
+ });
18
+ });
19
19
  //# sourceMappingURL=sort.js.map
@@ -1,13 +1,13 @@
1
- import { expect } from "chai";
2
- import { variance, scalar } from "../index";
3
- describe("variance", () => {
4
- it("scalarActivity", () => {
5
- const calcVariance = scalar(variance());
6
- expect(calcVariance([5, 1, 2, 3, 4])).to.equal(2.5);
7
- });
8
- it("empty array", () => {
9
- const varianceActivity = scalar(variance());
10
- expect(varianceActivity([])).to.be.undefined;
11
- });
12
- });
1
+ import { expect } from "chai";
2
+ import { variance, scalar } from "../index";
3
+ describe("variance", () => {
4
+ it("scalarActivity", () => {
5
+ const calcVariance = scalar(variance());
6
+ expect(calcVariance([5, 1, 2, 3, 4])).to.equal(2.5);
7
+ });
8
+ it("empty array", () => {
9
+ const varianceActivity = scalar(variance());
10
+ expect(varianceActivity([])).to.be.undefined;
11
+ });
12
+ });
13
13
  //# sourceMappingURL=variance.js.map
@@ -1,4 +1,4 @@
1
- export function isSource(source) {
2
- return typeof source[Symbol.iterator] === "function" || Array.isArray(source);
3
- }
1
+ export function isSource(source) {
2
+ return typeof source[Symbol.iterator] === "function" || Array.isArray(source);
3
+ }
4
4
  //# sourceMappingURL=activity.js.map
@@ -1,10 +1,10 @@
1
- function concatGen(concatSource) {
2
- return function* (source) {
3
- yield* source;
4
- yield* concatSource;
5
- };
6
- }
7
- export function concat(s_or_n, concatSource) {
8
- return concatSource !== undefined ? concatGen(concatSource)(s_or_n) : concatGen(s_or_n);
9
- }
1
+ function concatGen(concatSource) {
2
+ return function* (source) {
3
+ yield* source;
4
+ yield* concatSource;
5
+ };
6
+ }
7
+ export function concat(s_or_n, concatSource) {
8
+ return concatSource !== undefined ? concatGen(concatSource)(s_or_n) : concatGen(s_or_n);
9
+ }
10
10
  //# sourceMappingURL=concat.js.map
@@ -1,14 +1,14 @@
1
- import { isSource } from "./activity";
2
- function eachGen(callbackFn) {
3
- return function* (source) {
4
- let i = -1;
5
- for (const item of source) {
6
- callbackFn(item, ++i);
7
- yield item;
8
- }
9
- };
10
- }
11
- export function each(s_or_cb, callbackFn) {
12
- return isSource(s_or_cb) ? eachGen(callbackFn)(s_or_cb) : eachGen(s_or_cb);
13
- }
1
+ import { isSource } from "./activity";
2
+ function eachGen(callbackFn) {
3
+ return function* (source) {
4
+ let i = -1;
5
+ for (const item of source) {
6
+ callbackFn(item, ++i);
7
+ yield item;
8
+ }
9
+ };
10
+ }
11
+ export function each(s_or_cb, callbackFn) {
12
+ return isSource(s_or_cb) ? eachGen(callbackFn)(s_or_cb) : eachGen(s_or_cb);
13
+ }
14
14
  //# sourceMappingURL=each.js.map
@@ -1,13 +1,13 @@
1
- // Array.entries
2
- function entriesGen() {
3
- return function* (source) {
4
- let i = -1;
5
- for (const item of source) {
6
- yield [++i, item];
7
- }
8
- };
9
- }
10
- export function entries(source) {
11
- return source ? entriesGen()(source) : entriesGen();
12
- }
1
+ // Array.entries
2
+ function entriesGen() {
3
+ return function* (source) {
4
+ let i = -1;
5
+ for (const item of source) {
6
+ yield [++i, item];
7
+ }
8
+ };
9
+ }
10
+ export function entries(source) {
11
+ return source ? entriesGen()(source) : entriesGen();
12
+ }
13
13
  //# sourceMappingURL=entries.js.map