@hpcc-js/dataflow 9.1.0 → 9.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +43 -43
- package/README.md +530 -530
- package/dist/index.js.map +1 -1
- package/dist/index.min.js +1 -1
- package/dist/index.min.js.map +1 -1
- package/lib-es6/__package__.js +2 -2
- package/package.json +3 -3
- package/src/__package__.ts +3 -3
- package/src/__tests__/chain.ts +85 -85
- package/src/__tests__/concat.ts +18 -18
- package/src/__tests__/count.ts +25 -25
- package/src/__tests__/data.ts +64 -64
- package/src/__tests__/deviation.ts +14 -14
- package/src/__tests__/distribution.ts +21 -21
- package/src/__tests__/each.ts +13 -13
- package/src/__tests__/entries.ts +14 -14
- package/src/__tests__/extent.ts +25 -25
- package/src/__tests__/filter.ts +16 -16
- package/src/__tests__/first.ts +15 -15
- package/src/__tests__/generate.ts +9 -9
- package/src/__tests__/group.ts +19 -19
- package/src/__tests__/histogram.ts +47 -47
- package/src/__tests__/index.ts +27 -27
- package/src/__tests__/join.ts +20 -20
- package/src/__tests__/map.ts +16 -16
- package/src/__tests__/max.ts +42 -42
- package/src/__tests__/mean.ts +11 -11
- package/src/__tests__/median.ts +14 -14
- package/src/__tests__/min.ts +42 -42
- package/src/__tests__/normalize.ts +14 -14
- package/src/__tests__/quartile.ts +14 -14
- package/src/__tests__/readme.ts +113 -113
- package/src/__tests__/reduce.ts +17 -17
- package/src/__tests__/skip.ts +15 -15
- package/src/__tests__/sort.ts +21 -21
- package/src/__tests__/variance.ts +14 -14
- package/src/activities/activity.ts +8 -8
- package/src/activities/concat.ts +14 -14
- package/src/activities/each.ts +19 -19
- package/src/activities/entries.ts +17 -17
- package/src/activities/filter.ts +20 -20
- package/src/activities/first.ts +20 -20
- package/src/activities/group.ts +27 -27
- package/src/activities/histogram.ts +78 -78
- package/src/activities/join.ts +19 -19
- package/src/activities/map.ts +18 -18
- package/src/activities/normalize.ts +21 -21
- package/src/activities/skip.ts +18 -18
- package/src/activities/sort.ts +16 -16
- package/src/index.ts +27 -27
- package/src/observers/count.ts +15 -15
- package/src/observers/deviation.ts +24 -24
- package/src/observers/distribution.ts +51 -51
- package/src/observers/extent.ts +24 -24
- package/src/observers/max.ts +24 -24
- package/src/observers/mean.ts +26 -26
- package/src/observers/median.ts +30 -30
- package/src/observers/min.ts +24 -24
- package/src/observers/observer.ts +52 -52
- package/src/observers/quartile.ts +43 -43
- package/src/observers/reduce.ts +22 -22
- package/src/observers/variance.ts +29 -29
- package/src/utils/generate.ts +6 -6
- package/src/utils/pipe.ts +74 -74
- package/types/__package__.d.ts +2 -2
- package/types/observers/observer.d.ts.map +1 -1
- package/types-3.4/__package__.d.ts +2 -2
package/src/__tests__/readme.ts
CHANGED
|
@@ -1,113 +1,113 @@
|
|
|
1
|
-
import { expect } from "chai";
|
|
2
|
-
|
|
3
|
-
import { count, filter, first, generate, map, max, pipe, sensor } from "../index";
|
|
4
|
-
|
|
5
|
-
describe("readme", () => {
|
|
6
|
-
|
|
7
|
-
it("quick example", () => {
|
|
8
|
-
|
|
9
|
-
const c1 = count();
|
|
10
|
-
const c2 = count();
|
|
11
|
-
const c3 = count();
|
|
12
|
-
const m1 = max(row => row.value);
|
|
13
|
-
|
|
14
|
-
const p1 = pipe(
|
|
15
|
-
sensor(c1), // Keep running count of input
|
|
16
|
-
filter(n => n <= 0.5), // Filter out numbers > 0.5
|
|
17
|
-
sensor(c2), // Keep running count of filtered rows
|
|
18
|
-
map((n, idx) => // Convert to JSON Object
|
|
19
|
-
({ index: idx, value: n })),
|
|
20
|
-
filter(row => row.index % 2 === 0), // Filter even row indecies
|
|
21
|
-
sensor(c3), // Keep running count of final rows
|
|
22
|
-
sensor(m1), // Track largest value
|
|
23
|
-
first(3) // Take first 3 rows
|
|
24
|
-
);
|
|
25
|
-
|
|
26
|
-
console.info(`Counts: ${c1.peek()}, ${c2.peek()}, ${c3.peek()}`);
|
|
27
|
-
// [1] => Counts: undefined, undefined, undefined
|
|
28
|
-
const outIterable = p1(generate(Math.random, 1000));
|
|
29
|
-
console.info(`Counts: ${c1.peek()}, ${c2.peek()}, ${c3.peek()}`);
|
|
30
|
-
// [2] => Counts: undefined, undefined, undefined
|
|
31
|
-
console.info(JSON.stringify([...outIterable]));
|
|
32
|
-
// [3] => [{"index":0,"value":0.19075931906641008},{"index":2,"value":0.4873469062925415},{"index":4,"value":0.4412516774100035}]
|
|
33
|
-
console.info(`Counts: ${c1.peek()}, ${c2.peek()}, ${c3.peek()}, ${m1.peek()}`);
|
|
34
|
-
// [4] => Counts: 6, 5, 3, 0.4873469062925415
|
|
35
|
-
|
|
36
|
-
const outArray = [...p1([0.7, 0.5, 0.4, 0.8, 0.3, 1])];
|
|
37
|
-
console.info(JSON.stringify(outArray));
|
|
38
|
-
// [5] => [{"index":0,"value":0.5},{"index":2,"value":0.3}]
|
|
39
|
-
console.info(`Counts: ${c1.peek()}, ${c2.peek()}, ${c3.peek()}, ${m1.peek()}`);
|
|
40
|
-
// [6] => Counts: 6, 3, 2, 0.5
|
|
41
|
-
|
|
42
|
-
expect(outArray.length).to.equal(2);
|
|
43
|
-
|
|
44
|
-
for (const row of p1(generate(Math.random, 1000000))) {
|
|
45
|
-
console.info(`${row.index}: ${c1.peek()}, ${c2.peek()}, ${c3.peek()}, ${m1.peek()}`);
|
|
46
|
-
}
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
it("interesting example", () => {
|
|
50
|
-
const c1 = count();
|
|
51
|
-
const c2 = count();
|
|
52
|
-
const c3 = count();
|
|
53
|
-
const m1 = max(row => row.value);
|
|
54
|
-
|
|
55
|
-
const p1 = pipe(
|
|
56
|
-
sensor(c1), // Keep running count of input
|
|
57
|
-
filter(n => n <= 0.5), // Filter out numbers > 0.5
|
|
58
|
-
sensor(c2), // Keep running count of filtered rows
|
|
59
|
-
map((n, idx) => // Convert to JSON Object
|
|
60
|
-
({ index: idx, value: n })),
|
|
61
|
-
filter(row => row.index % 2 === 0), // Filter even row indecies
|
|
62
|
-
sensor(c3), // Keep running count of final rows
|
|
63
|
-
sensor(m1), // Track largest value
|
|
64
|
-
);
|
|
65
|
-
|
|
66
|
-
for (const row of p1(generate(Math.random, 1000000))) {
|
|
67
|
-
if (row.index % 100000 === 0) {
|
|
68
|
-
console.info(`${row.index}: ${c1.peek()}, ${c2.peek()}, ${c3.peek()}, ${m1.peek()}`);
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
});
|
|
72
|
-
});
|
|
73
|
-
|
|
74
|
-
/*
|
|
75
|
-
const process3 = pipe(
|
|
76
|
-
filter(n => n <= 0.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(...process3([]));
|
|
83
|
-
|
|
84
|
-
// Iterable output
|
|
85
|
-
pipe([0, 1, 2, 3, 4, 5, 6, 7, 8, 9],
|
|
86
|
-
filter(n => n <= 5),
|
|
87
|
-
map((n, idx) => ({ index: idx, value: n })),
|
|
88
|
-
filter(row => row.index % 2 === 0),
|
|
89
|
-
sort((l, r) => l.value - r.value),
|
|
90
|
-
first(3)
|
|
91
|
-
); // => { index: 0, value: 0 }, { index: 2, value: 2 }, { index: 4, value: 4 }
|
|
92
|
-
|
|
93
|
-
const process = pipe(
|
|
94
|
-
filter(n => n <= 5),
|
|
95
|
-
map((n, idx) => ({ index: idx, value: n })),
|
|
96
|
-
filter(row => row.index % 2 === 0),
|
|
97
|
-
sort((l, r) => l.value - r.value),
|
|
98
|
-
first(3)
|
|
99
|
-
);
|
|
100
|
-
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 }
|
|
101
|
-
|
|
102
|
-
// Scalar output
|
|
103
|
-
pipe([0, 1, 2, 3, 4, 5, 6, 7, 8, 9],
|
|
104
|
-
process,
|
|
105
|
-
scalar(max(row => row.value))
|
|
106
|
-
); // => 4
|
|
107
|
-
|
|
108
|
-
const process_2 = pipe(
|
|
109
|
-
process,
|
|
110
|
-
scalar(min(row => row.value))
|
|
111
|
-
);
|
|
112
|
-
console.log(process_2([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])); // => 0
|
|
113
|
-
*/
|
|
1
|
+
import { expect } from "chai";
|
|
2
|
+
|
|
3
|
+
import { count, filter, first, generate, map, max, pipe, sensor } from "../index";
|
|
4
|
+
|
|
5
|
+
describe("readme", () => {
|
|
6
|
+
|
|
7
|
+
it("quick example", () => {
|
|
8
|
+
|
|
9
|
+
const c1 = count();
|
|
10
|
+
const c2 = count();
|
|
11
|
+
const c3 = count();
|
|
12
|
+
const m1 = max(row => row.value);
|
|
13
|
+
|
|
14
|
+
const p1 = pipe(
|
|
15
|
+
sensor(c1), // Keep running count of input
|
|
16
|
+
filter(n => n <= 0.5), // Filter out numbers > 0.5
|
|
17
|
+
sensor(c2), // Keep running count of filtered rows
|
|
18
|
+
map((n, idx) => // Convert to JSON Object
|
|
19
|
+
({ index: idx, value: n })),
|
|
20
|
+
filter(row => row.index % 2 === 0), // Filter even row indecies
|
|
21
|
+
sensor(c3), // Keep running count of final rows
|
|
22
|
+
sensor(m1), // Track largest value
|
|
23
|
+
first(3) // Take first 3 rows
|
|
24
|
+
);
|
|
25
|
+
|
|
26
|
+
console.info(`Counts: ${c1.peek()}, ${c2.peek()}, ${c3.peek()}`);
|
|
27
|
+
// [1] => Counts: undefined, undefined, undefined
|
|
28
|
+
const outIterable = p1(generate(Math.random, 1000));
|
|
29
|
+
console.info(`Counts: ${c1.peek()}, ${c2.peek()}, ${c3.peek()}`);
|
|
30
|
+
// [2] => Counts: undefined, undefined, undefined
|
|
31
|
+
console.info(JSON.stringify([...outIterable]));
|
|
32
|
+
// [3] => [{"index":0,"value":0.19075931906641008},{"index":2,"value":0.4873469062925415},{"index":4,"value":0.4412516774100035}]
|
|
33
|
+
console.info(`Counts: ${c1.peek()}, ${c2.peek()}, ${c3.peek()}, ${m1.peek()}`);
|
|
34
|
+
// [4] => Counts: 6, 5, 3, 0.4873469062925415
|
|
35
|
+
|
|
36
|
+
const outArray = [...p1([0.7, 0.5, 0.4, 0.8, 0.3, 1])];
|
|
37
|
+
console.info(JSON.stringify(outArray));
|
|
38
|
+
// [5] => [{"index":0,"value":0.5},{"index":2,"value":0.3}]
|
|
39
|
+
console.info(`Counts: ${c1.peek()}, ${c2.peek()}, ${c3.peek()}, ${m1.peek()}`);
|
|
40
|
+
// [6] => Counts: 6, 3, 2, 0.5
|
|
41
|
+
|
|
42
|
+
expect(outArray.length).to.equal(2);
|
|
43
|
+
|
|
44
|
+
for (const row of p1(generate(Math.random, 1000000))) {
|
|
45
|
+
console.info(`${row.index}: ${c1.peek()}, ${c2.peek()}, ${c3.peek()}, ${m1.peek()}`);
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
it("interesting example", () => {
|
|
50
|
+
const c1 = count();
|
|
51
|
+
const c2 = count();
|
|
52
|
+
const c3 = count();
|
|
53
|
+
const m1 = max(row => row.value);
|
|
54
|
+
|
|
55
|
+
const p1 = pipe(
|
|
56
|
+
sensor(c1), // Keep running count of input
|
|
57
|
+
filter(n => n <= 0.5), // Filter out numbers > 0.5
|
|
58
|
+
sensor(c2), // Keep running count of filtered rows
|
|
59
|
+
map((n, idx) => // Convert to JSON Object
|
|
60
|
+
({ index: idx, value: n })),
|
|
61
|
+
filter(row => row.index % 2 === 0), // Filter even row indecies
|
|
62
|
+
sensor(c3), // Keep running count of final rows
|
|
63
|
+
sensor(m1), // Track largest value
|
|
64
|
+
);
|
|
65
|
+
|
|
66
|
+
for (const row of p1(generate(Math.random, 1000000))) {
|
|
67
|
+
if (row.index % 100000 === 0) {
|
|
68
|
+
console.info(`${row.index}: ${c1.peek()}, ${c2.peek()}, ${c3.peek()}, ${m1.peek()}`);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
/*
|
|
75
|
+
const process3 = pipe(
|
|
76
|
+
filter(n => n <= 0.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(...process3([]));
|
|
83
|
+
|
|
84
|
+
// Iterable output
|
|
85
|
+
pipe([0, 1, 2, 3, 4, 5, 6, 7, 8, 9],
|
|
86
|
+
filter(n => n <= 5),
|
|
87
|
+
map((n, idx) => ({ index: idx, value: n })),
|
|
88
|
+
filter(row => row.index % 2 === 0),
|
|
89
|
+
sort((l, r) => l.value - r.value),
|
|
90
|
+
first(3)
|
|
91
|
+
); // => { index: 0, value: 0 }, { index: 2, value: 2 }, { index: 4, value: 4 }
|
|
92
|
+
|
|
93
|
+
const process = pipe(
|
|
94
|
+
filter(n => n <= 5),
|
|
95
|
+
map((n, idx) => ({ index: idx, value: n })),
|
|
96
|
+
filter(row => row.index % 2 === 0),
|
|
97
|
+
sort((l, r) => l.value - r.value),
|
|
98
|
+
first(3)
|
|
99
|
+
);
|
|
100
|
+
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 }
|
|
101
|
+
|
|
102
|
+
// Scalar output
|
|
103
|
+
pipe([0, 1, 2, 3, 4, 5, 6, 7, 8, 9],
|
|
104
|
+
process,
|
|
105
|
+
scalar(max(row => row.value))
|
|
106
|
+
); // => 4
|
|
107
|
+
|
|
108
|
+
const process_2 = pipe(
|
|
109
|
+
process,
|
|
110
|
+
scalar(min(row => row.value))
|
|
111
|
+
);
|
|
112
|
+
console.log(process_2([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])); // => 0
|
|
113
|
+
*/
|
package/src/__tests__/reduce.ts
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
import { expect } from "chai";
|
|
2
|
-
import { reduce, scalar } from "../index";
|
|
3
|
-
|
|
4
|
-
const data = [1, 2, 3, 4, 5];
|
|
5
|
-
const reduceFunc = (prev, row) => prev + row;
|
|
6
|
-
const expectedA = data.reduce(reduceFunc);
|
|
7
|
-
const expectedB = data.reduce(reduceFunc, 10);
|
|
8
|
-
|
|
9
|
-
describe("reduce", () => {
|
|
10
|
-
|
|
11
|
-
it("scalarActivity", () => {
|
|
12
|
-
const calcReduce = scalar(reduce(reduceFunc));
|
|
13
|
-
const calcReduce2 = scalar(reduce(reduceFunc, 10));
|
|
14
|
-
expect(calcReduce(data)).to.equal(expectedA);
|
|
15
|
-
expect(calcReduce2(data)).to.equal(expectedB);
|
|
16
|
-
});
|
|
17
|
-
});
|
|
1
|
+
import { expect } from "chai";
|
|
2
|
+
import { reduce, scalar } from "../index";
|
|
3
|
+
|
|
4
|
+
const data = [1, 2, 3, 4, 5];
|
|
5
|
+
const reduceFunc = (prev, row) => prev + row;
|
|
6
|
+
const expectedA = data.reduce(reduceFunc);
|
|
7
|
+
const expectedB = data.reduce(reduceFunc, 10);
|
|
8
|
+
|
|
9
|
+
describe("reduce", () => {
|
|
10
|
+
|
|
11
|
+
it("scalarActivity", () => {
|
|
12
|
+
const calcReduce = scalar(reduce(reduceFunc));
|
|
13
|
+
const calcReduce2 = scalar(reduce(reduceFunc, 10));
|
|
14
|
+
expect(calcReduce(data)).to.equal(expectedA);
|
|
15
|
+
expect(calcReduce2(data)).to.equal(expectedB);
|
|
16
|
+
});
|
|
17
|
+
});
|
package/src/__tests__/skip.ts
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import { expect } from "chai";
|
|
2
|
-
import { skip } from "../index";
|
|
3
|
-
|
|
4
|
-
describe("skip", () => {
|
|
5
|
-
it("generator", () => {
|
|
6
|
-
expect([...skip(2)([])]).to.deep.equal([]);
|
|
7
|
-
expect([...skip(2)(["a", "b", "c"])]).to.deep.equal(["c"]);
|
|
8
|
-
});
|
|
9
|
-
|
|
10
|
-
it("scalarActivity", () => {
|
|
11
|
-
expect([...skip([], 22)]).to.deep.equal([]);
|
|
12
|
-
expect([...skip(["a", "b", "c"], 2)]).to.deep.equal(["c"]);
|
|
13
|
-
expect([...skip(["a", "b", "c"], 22)]).to.deep.equal([]);
|
|
14
|
-
});
|
|
15
|
-
});
|
|
1
|
+
import { expect } from "chai";
|
|
2
|
+
import { skip } from "../index";
|
|
3
|
+
|
|
4
|
+
describe("skip", () => {
|
|
5
|
+
it("generator", () => {
|
|
6
|
+
expect([...skip(2)([])]).to.deep.equal([]);
|
|
7
|
+
expect([...skip(2)(["a", "b", "c"])]).to.deep.equal(["c"]);
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
it("scalarActivity", () => {
|
|
11
|
+
expect([...skip([], 22)]).to.deep.equal([]);
|
|
12
|
+
expect([...skip(["a", "b", "c"], 2)]).to.deep.equal(["c"]);
|
|
13
|
+
expect([...skip(["a", "b", "c"], 22)]).to.deep.equal([]);
|
|
14
|
+
});
|
|
15
|
+
});
|
package/src/__tests__/sort.ts
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
import { expect } from "chai";
|
|
2
|
-
import { sort } from "../index";
|
|
3
|
-
import { Person, population } from "./data";
|
|
4
|
-
|
|
5
|
-
function sortFunc(l: Person, r: Person): number {
|
|
6
|
-
const retVal = l.lname.localeCompare(r.lname);
|
|
7
|
-
if (retVal === 0) return l.fname.localeCompare(r.fname);
|
|
8
|
-
return retVal;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
const expected = [...population].sort(sortFunc);
|
|
12
|
-
|
|
13
|
-
describe("sort", () => {
|
|
14
|
-
it("generator", () => {
|
|
15
|
-
expect([...sort(sortFunc)(population)]).to.deep.equal(expected);
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
it("scalarActivity", () => {
|
|
19
|
-
expect([...sort(population, sortFunc)]).to.deep.equal(expected);
|
|
20
|
-
});
|
|
21
|
-
});
|
|
1
|
+
import { expect } from "chai";
|
|
2
|
+
import { sort } from "../index";
|
|
3
|
+
import { Person, population } from "./data";
|
|
4
|
+
|
|
5
|
+
function sortFunc(l: Person, r: Person): number {
|
|
6
|
+
const retVal = l.lname.localeCompare(r.lname);
|
|
7
|
+
if (retVal === 0) return l.fname.localeCompare(r.fname);
|
|
8
|
+
return retVal;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
const expected = [...population].sort(sortFunc);
|
|
12
|
+
|
|
13
|
+
describe("sort", () => {
|
|
14
|
+
it("generator", () => {
|
|
15
|
+
expect([...sort(sortFunc)(population)]).to.deep.equal(expected);
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
it("scalarActivity", () => {
|
|
19
|
+
expect([...sort(population, sortFunc)]).to.deep.equal(expected);
|
|
20
|
+
});
|
|
21
|
+
});
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import { expect } from "chai";
|
|
2
|
-
import { variance, scalar } from "../index";
|
|
3
|
-
|
|
4
|
-
describe("variance", () => {
|
|
5
|
-
it("scalarActivity", () => {
|
|
6
|
-
const calcVariance = scalar(variance());
|
|
7
|
-
expect(calcVariance([5, 1, 2, 3, 4])).to.equal(2.5);
|
|
8
|
-
});
|
|
9
|
-
|
|
10
|
-
it("empty array", () => {
|
|
11
|
-
const varianceActivity = scalar(variance());
|
|
12
|
-
expect(varianceActivity([])).to.be.undefined;
|
|
13
|
-
});
|
|
14
|
-
});
|
|
1
|
+
import { expect } from "chai";
|
|
2
|
+
import { variance, scalar } from "../index";
|
|
3
|
+
|
|
4
|
+
describe("variance", () => {
|
|
5
|
+
it("scalarActivity", () => {
|
|
6
|
+
const calcVariance = scalar(variance());
|
|
7
|
+
expect(calcVariance([5, 1, 2, 3, 4])).to.equal(2.5);
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
it("empty array", () => {
|
|
11
|
+
const varianceActivity = scalar(variance());
|
|
12
|
+
expect(varianceActivity([])).to.be.undefined;
|
|
13
|
+
});
|
|
14
|
+
});
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
export type Source<T> = IterableIterator<T> | T[];
|
|
2
|
-
export type IterableActivity<T, U = T> = (source: Source<T>) => IterableIterator<U>;
|
|
3
|
-
export type ScalarActivity<T, U = T> = (source: Source<T>) => U;
|
|
4
|
-
export type Activity<T, U = T> = IterableActivity<T, U> | ScalarActivity<T, U>;
|
|
5
|
-
|
|
6
|
-
export function isSource<T>(source: Source<T> | any): source is Source<T> {
|
|
7
|
-
return source && (typeof source[Symbol.iterator] === "function" || Array.isArray(source));
|
|
8
|
-
}
|
|
1
|
+
export type Source<T> = IterableIterator<T> | T[];
|
|
2
|
+
export type IterableActivity<T, U = T> = (source: Source<T>) => IterableIterator<U>;
|
|
3
|
+
export type ScalarActivity<T, U = T> = (source: Source<T>) => U;
|
|
4
|
+
export type Activity<T, U = T> = IterableActivity<T, U> | ScalarActivity<T, U>;
|
|
5
|
+
|
|
6
|
+
export function isSource<T>(source: Source<T> | any): source is Source<T> {
|
|
7
|
+
return source && (typeof source[Symbol.iterator] === "function" || Array.isArray(source));
|
|
8
|
+
}
|
package/src/activities/concat.ts
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import { Source, IterableActivity } from "./activity";
|
|
2
|
-
|
|
3
|
-
function concatGen<T = any>(concatSource: Source<T>): IterableActivity<T> {
|
|
4
|
-
return function* (source: Source<T>) {
|
|
5
|
-
yield* source;
|
|
6
|
-
yield* concatSource;
|
|
7
|
-
};
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
export function concat<T = any>(concatSource: Source<T>): IterableActivity<T, T>;
|
|
11
|
-
export function concat<T>(source: Source<T>, concatSource: Source<T>): IterableIterator<T>;
|
|
12
|
-
export function concat<T = any>(s_or_n: Source<T>, concatSource?: Source<T>): IterableActivity<T, T> | IterableIterator<T> {
|
|
13
|
-
return concatSource !== undefined ? concatGen<T>(concatSource!)(s_or_n) : concatGen<T>(s_or_n);
|
|
14
|
-
}
|
|
1
|
+
import { Source, IterableActivity } from "./activity";
|
|
2
|
+
|
|
3
|
+
function concatGen<T = any>(concatSource: Source<T>): IterableActivity<T> {
|
|
4
|
+
return function* (source: Source<T>) {
|
|
5
|
+
yield* source;
|
|
6
|
+
yield* concatSource;
|
|
7
|
+
};
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export function concat<T = any>(concatSource: Source<T>): IterableActivity<T, T>;
|
|
11
|
+
export function concat<T>(source: Source<T>, concatSource: Source<T>): IterableIterator<T>;
|
|
12
|
+
export function concat<T = any>(s_or_n: Source<T>, concatSource?: Source<T>): IterableActivity<T, T> | IterableIterator<T> {
|
|
13
|
+
return concatSource !== undefined ? concatGen<T>(concatSource!)(s_or_n) : concatGen<T>(s_or_n);
|
|
14
|
+
}
|
package/src/activities/each.ts
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
import { IterableActivity, Source, isSource } from "./activity";
|
|
2
|
-
|
|
3
|
-
export type EachCallback<T> = (value: T, index: number) => void;
|
|
4
|
-
|
|
5
|
-
function eachGen<T = any>(callbackFn: EachCallback<T>): IterableActivity<T> {
|
|
6
|
-
return function* (source: Source<T>) {
|
|
7
|
-
let i = -1;
|
|
8
|
-
for (const item of source) {
|
|
9
|
-
callbackFn(item, ++i);
|
|
10
|
-
yield item;
|
|
11
|
-
}
|
|
12
|
-
};
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export function each<T = any>(callbackFn: EachCallback<T>): IterableActivity<T>;
|
|
16
|
-
export function each<T>(source: Source<T>, callbackFn: EachCallback<T>): IterableIterator<T>;
|
|
17
|
-
export function each<T>(s_or_cb: Source<T> | EachCallback<T>, callbackFn?: EachCallback<T>): IterableActivity<T> | IterableIterator<T> {
|
|
18
|
-
return isSource(s_or_cb) ? eachGen(callbackFn!)(s_or_cb) : eachGen(s_or_cb);
|
|
19
|
-
}
|
|
1
|
+
import { IterableActivity, Source, isSource } from "./activity";
|
|
2
|
+
|
|
3
|
+
export type EachCallback<T> = (value: T, index: number) => void;
|
|
4
|
+
|
|
5
|
+
function eachGen<T = any>(callbackFn: EachCallback<T>): IterableActivity<T> {
|
|
6
|
+
return function* (source: Source<T>) {
|
|
7
|
+
let i = -1;
|
|
8
|
+
for (const item of source) {
|
|
9
|
+
callbackFn(item, ++i);
|
|
10
|
+
yield item;
|
|
11
|
+
}
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export function each<T = any>(callbackFn: EachCallback<T>): IterableActivity<T>;
|
|
16
|
+
export function each<T>(source: Source<T>, callbackFn: EachCallback<T>): IterableIterator<T>;
|
|
17
|
+
export function each<T>(s_or_cb: Source<T> | EachCallback<T>, callbackFn?: EachCallback<T>): IterableActivity<T> | IterableIterator<T> {
|
|
18
|
+
return isSource(s_or_cb) ? eachGen(callbackFn!)(s_or_cb) : eachGen(s_or_cb);
|
|
19
|
+
}
|
|
@@ -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
|
+
}
|
package/src/activities/filter.ts
CHANGED
|
@@ -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
|
+
}
|
package/src/activities/first.ts
CHANGED
|
@@ -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
|
+
}
|
package/src/activities/group.ts
CHANGED
|
@@ -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
|
+
}
|