@thi.ng/transducers 9.0.5 → 9.0.6
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/CHANGELOG.md +9 -1
- package/README.md +4 -2
- package/add.d.ts +2 -2
- package/add.js +2 -2
- package/api.d.ts +11 -6
- package/assoc-map.d.ts +2 -2
- package/assoc-map.js +2 -2
- package/assoc-obj.d.ts +2 -2
- package/assoc-obj.js +2 -2
- package/auto-obj.d.ts +5 -3
- package/auto-obj.js +2 -2
- package/benchmark.d.ts +9 -3
- package/cat.d.ts +19 -13
- package/cat.js +1 -1
- package/choices.d.ts +14 -3
- package/concat.d.ts +9 -5
- package/concat.js +3 -3
- package/conj.d.ts +1 -1
- package/conj.js +2 -2
- package/consume.d.ts +6 -2
- package/converge.d.ts +5 -3
- package/convolve.js +7 -7
- package/count.d.ts +3 -3
- package/curve.d.ts +6 -4
- package/cycle.d.ts +7 -3
- package/dedupe.d.ts +4 -2
- package/deep-transform.d.ts +9 -8
- package/distinct.d.ts +4 -2
- package/div.d.ts +1 -1
- package/div.js +2 -2
- package/dup.d.ts +10 -5
- package/every.d.ts +6 -4
- package/every.js +1 -3
- package/extend-sides.d.ts +12 -4
- package/fill.d.ts +4 -4
- package/fill.js +1 -3
- package/filter-fuzzy.d.ts +4 -2
- package/flatten-with.d.ts +6 -3
- package/flatten.d.ts +7 -3
- package/flatten1.d.ts +11 -5
- package/frequencies.d.ts +2 -2
- package/group-binary.d.ts +37 -27
- package/group-binary.js +3 -3
- package/group-by-map.d.ts +2 -2
- package/group-by-obj.d.ts +54 -2
- package/internal/mathop.d.ts +11 -1
- package/internal/mathop.js +12 -5
- package/interpolate.d.ts +4 -3
- package/iterate.d.ts +7 -3
- package/iterator.d.ts +4 -4
- package/iterator.js +4 -4
- package/juxtr.d.ts +8 -2
- package/key-permutations.d.ts +4 -2
- package/last.d.ts +1 -1
- package/last.js +2 -2
- package/length.d.ts +4 -2
- package/line.d.ts +4 -2
- package/lookup.d.ts +8 -4
- package/map-indexed.d.ts +6 -8
- package/map-keys.d.ts +5 -3
- package/map-nth.d.ts +10 -6
- package/map-vals.d.ts +4 -2
- package/map.d.ts +4 -2
- package/mapcat.d.ts +10 -6
- package/match-first.d.ts +16 -17
- package/match-last.d.ts +12 -8
- package/max-compare.d.ts +3 -3
- package/max-compare.js +2 -9
- package/max-mag.d.ts +1 -1
- package/max-mag.js +2 -2
- package/max.d.ts +1 -1
- package/max.js +2 -2
- package/mean.d.ts +1 -1
- package/mean.js +2 -2
- package/min-compare.d.ts +3 -3
- package/min-compare.js +2 -9
- package/min-mag.d.ts +1 -1
- package/min-mag.js +2 -2
- package/min.d.ts +1 -1
- package/min.js +2 -2
- package/mul.d.ts +2 -2
- package/mul.js +2 -2
- package/multiplex-obj.d.ts +10 -6
- package/multiplex.d.ts +8 -6
- package/norm-count.d.ts +5 -3
- package/norm-frequencies-auto.d.ts +9 -5
- package/norm-frequencies.d.ts +13 -5
- package/norm-range.d.ts +13 -5
- package/package.json +14 -14
- package/pad-last.d.ts +24 -15
- package/pad-sides.d.ts +27 -5
- package/page.d.ts +13 -5
- package/pairs.d.ts +6 -3
- package/palindrome.d.ts +19 -6
- package/palindrome.js +2 -2
- package/partition-by.d.ts +4 -2
- package/partition-of.d.ts +5 -3
- package/partition-sort.d.ts +10 -4
- package/partition-sync.d.ts +15 -6
- package/partition-sync.js +6 -6
- package/partition-time.d.ts +5 -3
- package/partition-when.d.ts +4 -2
- package/partition.d.ts +11 -5
- package/peek.d.ts +5 -3
- package/permutations.d.ts +21 -9
- package/pluck.d.ts +4 -2
- package/push-sort.d.ts +1 -1
- package/push-sort.js +2 -2
- package/push.d.ts +4 -1
- package/push.js +2 -2
- package/range-nd.d.ts +13 -5
- package/rechunk.d.ts +9 -6
- package/reduce.d.ts +6 -6
- package/reduce.js +13 -13
- package/reductions.d.ts +1 -1
- package/reductions.js +2 -2
- package/repeat.d.ts +4 -2
- package/repeatedly.d.ts +7 -3
- package/repeatedly2d.d.ts +4 -2
- package/repeatedly3d.d.ts +4 -2
- package/reverse.d.ts +4 -2
- package/run.d.ts +10 -10
- package/sample.d.ts +4 -2
- package/scan.d.ts +20 -16
- package/select-keys.d.ts +5 -3
- package/sliding-window.d.ts +9 -3
- package/some.d.ts +2 -2
- package/step.d.ts +32 -17
- package/str.d.ts +7 -1
- package/str.js +2 -2
- package/stream-shuffle.d.ts +7 -3
- package/stream-sort.d.ts +6 -4
- package/struct.d.ts +14 -7
- package/sub.d.ts +2 -2
- package/sub.js +2 -2
- package/swizzle.d.ts +10 -4
- package/symmetric.d.ts +13 -3
- package/take-last.d.ts +4 -2
- package/take-nth.d.ts +4 -2
- package/take-while.d.ts +4 -2
- package/take.d.ts +8 -3
- package/toggle.d.ts +7 -3
- package/transduce.d.ts +6 -6
- package/transduce.js +4 -4
- package/tween.d.ts +22 -18
- package/zip.d.ts +9 -5
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@thi.ng/transducers",
|
|
3
|
-
"version": "9.0.
|
|
3
|
+
"version": "9.0.6",
|
|
4
4
|
"description": "Lightweight transducer implementations for ES6 / TypeScript",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"module": "./index.js",
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
"type": "git",
|
|
11
11
|
"url": "https://github.com/thi-ng/umbrella.git"
|
|
12
12
|
},
|
|
13
|
-
"homepage": "https://
|
|
13
|
+
"homepage": "https://thi.ng/transducers",
|
|
14
14
|
"funding": [
|
|
15
15
|
{
|
|
16
16
|
"type": "github",
|
|
@@ -40,20 +40,20 @@
|
|
|
40
40
|
"tool:tangle": "../../node_modules/.bin/tangle src/**/*.ts"
|
|
41
41
|
},
|
|
42
42
|
"dependencies": {
|
|
43
|
-
"@thi.ng/api": "^8.11.
|
|
44
|
-
"@thi.ng/arrays": "^2.9.
|
|
45
|
-
"@thi.ng/checks": "^3.6.
|
|
46
|
-
"@thi.ng/compare": "^2.3.
|
|
47
|
-
"@thi.ng/compose": "^3.0.
|
|
48
|
-
"@thi.ng/errors": "^2.5.
|
|
49
|
-
"@thi.ng/math": "^5.
|
|
50
|
-
"@thi.ng/random": "^3.8.
|
|
43
|
+
"@thi.ng/api": "^8.11.3",
|
|
44
|
+
"@thi.ng/arrays": "^2.9.7",
|
|
45
|
+
"@thi.ng/checks": "^3.6.5",
|
|
46
|
+
"@thi.ng/compare": "^2.3.6",
|
|
47
|
+
"@thi.ng/compose": "^3.0.5",
|
|
48
|
+
"@thi.ng/errors": "^2.5.8",
|
|
49
|
+
"@thi.ng/math": "^5.11.0",
|
|
50
|
+
"@thi.ng/random": "^3.8.1"
|
|
51
51
|
},
|
|
52
52
|
"devDependencies": {
|
|
53
|
-
"@microsoft/api-extractor": "^7.
|
|
54
|
-
"esbuild": "^0.21.
|
|
53
|
+
"@microsoft/api-extractor": "^7.47.0",
|
|
54
|
+
"esbuild": "^0.21.5",
|
|
55
55
|
"typedoc": "^0.25.13",
|
|
56
|
-
"typescript": "^5.
|
|
56
|
+
"typescript": "^5.5.2"
|
|
57
57
|
},
|
|
58
58
|
"keywords": [
|
|
59
59
|
"2d",
|
|
@@ -589,5 +589,5 @@
|
|
|
589
589
|
],
|
|
590
590
|
"year": 2016
|
|
591
591
|
},
|
|
592
|
-
"gitHead": "
|
|
592
|
+
"gitHead": "154c95cf9d6bab32174498ec3b5b5d87e42be7f9\n"
|
|
593
593
|
}
|
package/pad-last.d.ts
CHANGED
|
@@ -1,33 +1,42 @@
|
|
|
1
1
|
import type { Transducer } from "./api.js";
|
|
2
2
|
/**
|
|
3
|
-
* Ensures the total number of transformed values will be multiples of
|
|
4
|
-
* `n`.
|
|
3
|
+
* Ensures the total number of transformed values will be multiples of `n`.
|
|
5
4
|
*
|
|
6
5
|
* @remarks
|
|
7
|
-
* Only makes sense for finite streams / reductions. Does nothing if the
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
6
|
+
* Only makes sense for finite streams / reductions. Does nothing if the to be
|
|
7
|
+
* transformed data source has exactly multiple of `n` values, but if not pads /
|
|
8
|
+
* supplies additional `fill` values at the end until the next multiple is
|
|
9
|
+
* reached. No padding takes place if input is empty, since length 0 is always a
|
|
10
|
+
* multiple.
|
|
12
11
|
*
|
|
13
12
|
* @example
|
|
14
|
-
* ```ts
|
|
13
|
+
* ```ts tangle:../export/pad-last.ts
|
|
15
14
|
* import { padLast } from "@thi.ng/transducers";
|
|
16
15
|
*
|
|
17
|
-
*
|
|
16
|
+
* console.log(
|
|
17
|
+
* [...padLast(8, 0, [1, 2, 3, 4, 5])]
|
|
18
|
+
* );
|
|
18
19
|
* // [ 1, 2, 3, 4, 5, 0, 0, 0 ]
|
|
19
20
|
*
|
|
20
|
-
*
|
|
21
|
+
* console.log(
|
|
22
|
+
* [...padLast(8, 0, [1])]
|
|
23
|
+
* );
|
|
21
24
|
* // [ 1, 0, 0, 0, 0, 0, 0, 0 ]
|
|
22
25
|
*
|
|
23
|
-
*
|
|
26
|
+
* console.log(
|
|
27
|
+
* [...padLast(8, 0, [])]
|
|
28
|
+
* );
|
|
24
29
|
* // []
|
|
25
30
|
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
31
|
+
* console.log(
|
|
32
|
+
* [...padLast(4, 0, [1, 2])]
|
|
33
|
+
* );
|
|
34
|
+
* // [ 1, 2, 0, 0 ]
|
|
28
35
|
*
|
|
29
|
-
*
|
|
30
|
-
*
|
|
36
|
+
* console.log(
|
|
37
|
+
* [...padLast(4, 0, [1, 2, 3, 4, 5])]
|
|
38
|
+
* );
|
|
39
|
+
* // [ 1, 2, 3, 4, 5, 0, 0, 0 ]
|
|
31
40
|
* ```
|
|
32
41
|
*
|
|
33
42
|
* @param n -
|
package/pad-sides.d.ts
CHANGED
|
@@ -9,17 +9,39 @@
|
|
|
9
9
|
* {@link wrapSides}.
|
|
10
10
|
*
|
|
11
11
|
* @example
|
|
12
|
-
* ```ts
|
|
13
|
-
* import {
|
|
12
|
+
* ```ts tangle:../export/pad-sides.ts
|
|
13
|
+
* import { padSides, range } from "@thi.ng/transducers";
|
|
14
|
+
*
|
|
15
|
+
* // pad both sides with 10
|
|
16
|
+
* console.log(
|
|
17
|
+
* [...padSides(range(3), 10)]
|
|
18
|
+
* );
|
|
19
|
+
*
|
|
20
|
+
* // pad both sides 3x
|
|
21
|
+
* console.log(
|
|
22
|
+
* [...padSides(range(3), 10, 3)]
|
|
23
|
+
* );
|
|
24
|
+
*
|
|
25
|
+
* // left/start only
|
|
26
|
+
* console.log(
|
|
27
|
+
* [...padSides(range(3), 10, 3, 0)]
|
|
28
|
+
* );
|
|
29
|
+
*
|
|
30
|
+
* // right/end only
|
|
31
|
+
* console.log(
|
|
32
|
+
* [...padSides(range(3), 10, 0, 3)]
|
|
33
|
+
* );
|
|
34
|
+
*
|
|
35
|
+
* // padSides() is syntax sugar for:
|
|
14
36
|
*
|
|
15
37
|
* // default
|
|
16
|
-
* concat(repeat(x, numLeft), src, repeat(x, numRight))
|
|
38
|
+
* // concat(repeat(x, numLeft), src, repeat(x, numRight))
|
|
17
39
|
*
|
|
18
40
|
* // left only
|
|
19
|
-
* concat(repeat(x, numLeft), src)
|
|
41
|
+
* // concat(repeat(x, numLeft), src)
|
|
20
42
|
*
|
|
21
43
|
* // right only
|
|
22
|
-
* concat(src, repeat(x, numRight))
|
|
44
|
+
* // concat(src, repeat(x, numRight))
|
|
23
45
|
* ```
|
|
24
46
|
*
|
|
25
47
|
* @param src -
|
package/page.d.ts
CHANGED
|
@@ -8,19 +8,27 @@ import type { Transducer } from "./api.js";
|
|
|
8
8
|
* is used as early as possible / prior to any heavy processing steps.
|
|
9
9
|
*
|
|
10
10
|
* @example
|
|
11
|
-
* ```ts
|
|
11
|
+
* ```ts tangle:../export/page.ts
|
|
12
12
|
* import { page, range } from "@thi.ng/transducers";
|
|
13
13
|
*
|
|
14
|
-
*
|
|
14
|
+
* console.log(
|
|
15
|
+
* [...page(0, 5, range(12))]
|
|
16
|
+
* );
|
|
15
17
|
* // [ 0, 1, 2, 3, 4 ]
|
|
16
18
|
*
|
|
17
|
-
*
|
|
19
|
+
* console.log(
|
|
20
|
+
* [...page(1, 5, range(12))]
|
|
21
|
+
* );
|
|
18
22
|
* // [ 5, 6, 7, 8, 9 ]
|
|
19
23
|
*
|
|
20
|
-
*
|
|
24
|
+
* console.log(
|
|
25
|
+
* [...page(2, 5, range(12))]
|
|
26
|
+
* );
|
|
21
27
|
* // [ 10, 11 ]
|
|
22
28
|
*
|
|
23
|
-
*
|
|
29
|
+
* console.log(
|
|
30
|
+
* [...page(3, 5, range(12))]
|
|
31
|
+
* );
|
|
24
32
|
* // []
|
|
25
33
|
* ```
|
|
26
34
|
*
|
package/pairs.d.ts
CHANGED
|
@@ -1,17 +1,20 @@
|
|
|
1
1
|
import type { IObjectOf } from "@thi.ng/api";
|
|
2
2
|
/**
|
|
3
3
|
* Iterator yielding key-value pairs of given object's own properties and their
|
|
4
|
-
* values. Same as `zip(keys(x), vals(x))
|
|
4
|
+
* values. Same as `zip(keys(x), vals(x))` or iterator version of
|
|
5
|
+
* `Object.entries(x)`.
|
|
5
6
|
*
|
|
6
7
|
* @remarks
|
|
7
8
|
* - {@link vals}
|
|
8
9
|
* - {@link zip}
|
|
9
10
|
*
|
|
10
11
|
* @example
|
|
11
|
-
* ```ts
|
|
12
|
+
* ```ts tangle:../export/pairs.ts
|
|
12
13
|
* import { pairs } from "@thi.ng/transducers";
|
|
13
14
|
*
|
|
14
|
-
*
|
|
15
|
+
* console.log(
|
|
16
|
+
* [...pairs({ a: 1, b: 2 })]
|
|
17
|
+
* );
|
|
15
18
|
* // [['a', 1], ['b', 2]]
|
|
16
19
|
* ```
|
|
17
20
|
*
|
package/palindrome.d.ts
CHANGED
|
@@ -4,15 +4,28 @@
|
|
|
4
4
|
*
|
|
5
5
|
* @remarks
|
|
6
6
|
* In the general case, this is similar to `concat(x, reverse(x))`,
|
|
7
|
-
* though keeps input type intact.
|
|
7
|
+
* though this function keeps input type intact.
|
|
8
|
+
*
|
|
9
|
+
* Uses {@link symmetric}.for all inputs other than arrays or strings.
|
|
8
10
|
*
|
|
9
11
|
* @example
|
|
10
|
-
* ```ts
|
|
11
|
-
* import { palindrome } from "@thi.ng/transducers";
|
|
12
|
+
* ```ts tangle:../export/palindrome.ts
|
|
13
|
+
* import { palindrome, range } from "@thi.ng/transducers";
|
|
14
|
+
*
|
|
15
|
+
* console.log(
|
|
16
|
+
* palindrome("hello")
|
|
17
|
+
* );
|
|
18
|
+
* // "helloolleh"
|
|
19
|
+
*
|
|
20
|
+
* console.log(
|
|
21
|
+
* palindrome([1, 2, 3])
|
|
22
|
+
* );
|
|
23
|
+
* // [1, 2, 3, 3, 2, 1]
|
|
12
24
|
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
25
|
+
* console.log(
|
|
26
|
+
* [...palindrome(range(3))]
|
|
27
|
+
* );
|
|
28
|
+
* // [ 0, 1, 2, 2, 1, 0 ]
|
|
16
29
|
* ```
|
|
17
30
|
*
|
|
18
31
|
* @param x -
|
package/palindrome.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { ensureArray } from "@thi.ng/arrays/ensure-array";
|
|
2
1
|
import { isArray } from "@thi.ng/checks/is-array";
|
|
3
2
|
import { isString } from "@thi.ng/checks/is-string";
|
|
4
3
|
import { concat } from "./concat.js";
|
|
5
4
|
import { reverse } from "./reverse.js";
|
|
6
5
|
import { str } from "./str.js";
|
|
6
|
+
import { symmetric } from "./symmetric.js";
|
|
7
7
|
function palindrome(x) {
|
|
8
|
-
return isString(x) ? str("", concat([x], reverse(x))) : isArray(x) ? x.concat(x.slice().reverse()) : (x
|
|
8
|
+
return isString(x) ? str("", concat([x], reverse(x))) : isArray(x) ? x.concat(x.slice().reverse()) : symmetric(x);
|
|
9
9
|
}
|
|
10
10
|
export {
|
|
11
11
|
palindrome
|
package/partition-by.d.ts
CHANGED
|
@@ -6,10 +6,12 @@ import type { Transducer } from "./api.js";
|
|
|
6
6
|
* happens yields chunk of buffered values.
|
|
7
7
|
*
|
|
8
8
|
* @example
|
|
9
|
-
* ```ts
|
|
9
|
+
* ```ts tangle:../export/partition-by.ts
|
|
10
10
|
* import { partitionBy } from "@thi.ng/transducers";
|
|
11
11
|
*
|
|
12
|
-
*
|
|
12
|
+
* console.log(
|
|
13
|
+
* [...partitionBy((x) => x & 1, [1, 2, 4, 6, 3, 5, 8, 4])]
|
|
14
|
+
* );
|
|
13
15
|
* // [ [ 1 ], [ 2, 4, 6 ], [ 3, 5 ], [ 8, 4 ] ]
|
|
14
16
|
* ```
|
|
15
17
|
*
|
package/partition-of.d.ts
CHANGED
|
@@ -4,10 +4,12 @@ import type { Transducer } from "./api.js";
|
|
|
4
4
|
* chunks. The last partition emitted is allowed to be incomplete.
|
|
5
5
|
*
|
|
6
6
|
* @example
|
|
7
|
-
* ```ts
|
|
8
|
-
* import { partitionOf } from "@thi.ng/transducers";
|
|
7
|
+
* ```ts tangle:../export/partition-of.ts
|
|
8
|
+
* import { partitionOf, range } from "@thi.ng/transducers";
|
|
9
9
|
*
|
|
10
|
-
*
|
|
10
|
+
* console.log(
|
|
11
|
+
* [...partitionOf([3, 2, 4], range(20))]
|
|
12
|
+
* );
|
|
11
13
|
* // [ [ 0, 1, 2 ],
|
|
12
14
|
* // [ 3, 4 ],
|
|
13
15
|
* // [ 5, 6, 7, 8 ],
|
package/partition-sort.d.ts
CHANGED
|
@@ -10,20 +10,26 @@ import type { SortOpts, Transducer } from "./api.js";
|
|
|
10
10
|
* compute a sortable value and change sorting behavior.
|
|
11
11
|
*
|
|
12
12
|
* @example
|
|
13
|
-
* ```ts
|
|
13
|
+
* ```ts tangle:../export/partition-sort.ts
|
|
14
14
|
* import { partitionSort } from "@thi.ng/transducers";
|
|
15
15
|
*
|
|
16
|
-
*
|
|
16
|
+
* console.log(
|
|
17
|
+
* [...partitionSort(4, [5, 9, 2, 6, 4, 1, 3, 8, 7, 0])]
|
|
18
|
+
* );
|
|
17
19
|
* // [ 2, 5, 6, 9, 1, 3, 4, 8, 0, 7 ]
|
|
18
20
|
*
|
|
19
21
|
* // with key fn and custom comparator
|
|
20
|
-
* [...partitionSort(
|
|
22
|
+
* const res = [...partitionSort(
|
|
23
|
+
* 3,
|
|
24
|
+
* { key: (x) => x.val, compare: (a, b) => b - a },
|
|
21
25
|
* [
|
|
22
26
|
* { id: "a", val: 5 },
|
|
23
27
|
* { id: "b", val: 7 },
|
|
24
28
|
* { id: "c", val: 8 }
|
|
25
29
|
* ]
|
|
26
|
-
* )]
|
|
30
|
+
* )];
|
|
31
|
+
*
|
|
32
|
+
* console.log(res);
|
|
27
33
|
* // [ { id: 'c', val: 8 }, { id: 'b', val: 7 }, { id: 'a', val: 5 } ]
|
|
28
34
|
* ```
|
|
29
35
|
*
|
package/partition-sync.d.ts
CHANGED
|
@@ -68,17 +68,19 @@ export interface PartitionSyncOpts<T> {
|
|
|
68
68
|
* via `.add(id)` or `.delete(id)` on the returned transducer.
|
|
69
69
|
*
|
|
70
70
|
* @example
|
|
71
|
-
* ```ts
|
|
71
|
+
* ```ts tangle:../export/partition-sync.ts
|
|
72
72
|
* import { partitionSync } from "@thi.ng/transducers";
|
|
73
73
|
*
|
|
74
|
-
* src = [
|
|
74
|
+
* const src = [
|
|
75
75
|
* ["a", 1], ["a", 2], ["d", 100], ["b", 10],
|
|
76
76
|
* ["b", 11], ["c", 0], ["a", 3]
|
|
77
77
|
* ];
|
|
78
78
|
*
|
|
79
79
|
* // form tuples for values only from sources "a" & "b"
|
|
80
80
|
* // here the label is the first element of each input item
|
|
81
|
-
*
|
|
81
|
+
* console.log(
|
|
82
|
+
* [...partitionSync(["a", "b"], { key: (x) => x[0] }, src)]
|
|
83
|
+
* );
|
|
82
84
|
* // [ { a: ["a", 2], b: ["b", 10] },
|
|
83
85
|
* // { b: ["b", 11], a: ["a", 3] } ]
|
|
84
86
|
* ```
|
|
@@ -91,18 +93,25 @@ export interface PartitionSyncOpts<T> {
|
|
|
91
93
|
* above example:
|
|
92
94
|
*
|
|
93
95
|
* @example
|
|
94
|
-
* ```ts
|
|
96
|
+
* ```ts tangle:../export/partition-sync-2.ts
|
|
95
97
|
* import { partitionSync } from "@thi.ng/transducers";
|
|
96
98
|
*
|
|
99
|
+
* const src = [
|
|
100
|
+
* ["a", 1], ["a", 2], ["d", 100], ["b", 10],
|
|
101
|
+
* ["b", 11], ["c", 0], ["a", 3]
|
|
102
|
+
* ];
|
|
103
|
+
*
|
|
97
104
|
* // passing `false` to disable tuple reset
|
|
98
|
-
* [...partitionSync(
|
|
105
|
+
* const res = [...partitionSync(
|
|
99
106
|
* ["a", "b"],
|
|
100
107
|
* {
|
|
101
108
|
* key: (x) => x[0],
|
|
102
109
|
* reset: false
|
|
103
110
|
* },
|
|
104
111
|
* src
|
|
105
|
-
* )]
|
|
112
|
+
* )];
|
|
113
|
+
*
|
|
114
|
+
* console.log(res);
|
|
106
115
|
* // [ { a: ["a", 2], b: ["b", 10] },
|
|
107
116
|
* // { a: ["a", 2], b: ["b", 11] },
|
|
108
117
|
* // { a: ["a", 3], b: ["b", 11] } ]
|
package/partition-sync.js
CHANGED
|
@@ -36,7 +36,7 @@ function partitionSync(...args) {
|
|
|
36
36
|
if (requiredKeys.has(k)) {
|
|
37
37
|
curr[k] = x;
|
|
38
38
|
currKeys.add(k);
|
|
39
|
-
if (mergeOnly ||
|
|
39
|
+
if (mergeOnly || __requiredInputs(requiredKeys, currKeys)) {
|
|
40
40
|
acc = reduce(acc, curr);
|
|
41
41
|
first = false;
|
|
42
42
|
if (reset) {
|
|
@@ -55,7 +55,7 @@ function partitionSync(...args) {
|
|
|
55
55
|
init,
|
|
56
56
|
(acc) => {
|
|
57
57
|
if (all && currKeys.size > 0) {
|
|
58
|
-
acc = reduce(acc,
|
|
58
|
+
acc = reduce(acc, __collect(cache, currKeys));
|
|
59
59
|
cache.clear();
|
|
60
60
|
currKeys.clear();
|
|
61
61
|
}
|
|
@@ -73,8 +73,8 @@ function partitionSync(...args) {
|
|
|
73
73
|
);
|
|
74
74
|
slot.push(x);
|
|
75
75
|
currKeys.add(k);
|
|
76
|
-
while (
|
|
77
|
-
acc = reduce(acc,
|
|
76
|
+
while (__requiredInputs(requiredKeys, currKeys)) {
|
|
77
|
+
acc = reduce(acc, __collect(cache, currKeys));
|
|
78
78
|
first = false;
|
|
79
79
|
if (isReduced(acc)) break;
|
|
80
80
|
}
|
|
@@ -104,14 +104,14 @@ function partitionSync(...args) {
|
|
|
104
104
|
};
|
|
105
105
|
return xform;
|
|
106
106
|
}
|
|
107
|
-
const
|
|
107
|
+
const __requiredInputs = (required, curr) => {
|
|
108
108
|
if (curr.size < required.size) return false;
|
|
109
109
|
for (let id of required) {
|
|
110
110
|
if (!curr.has(id)) return false;
|
|
111
111
|
}
|
|
112
112
|
return true;
|
|
113
113
|
};
|
|
114
|
-
const
|
|
114
|
+
const __collect = (cache, currKeys) => {
|
|
115
115
|
const curr = {};
|
|
116
116
|
for (let id of currKeys) {
|
|
117
117
|
const slot = cache.get(id);
|
package/partition-time.d.ts
CHANGED
|
@@ -8,14 +8,16 @@ import type { Transducer } from "./api.js";
|
|
|
8
8
|
* Only to be used in async contexts, NOT with {@link transduce} directly.
|
|
9
9
|
*
|
|
10
10
|
* Also see:
|
|
11
|
+
* - [`thi.ng/transducers-async`](https://thi.ng/transducers-async).
|
|
11
12
|
* - [`thi.ng/rstream`](https://thi.ng/rstream)
|
|
12
|
-
* - [`thi.ng/csp`](https://thi.ng/csp).
|
|
13
13
|
*
|
|
14
14
|
* @example
|
|
15
|
-
* ```ts
|
|
15
|
+
* ```ts tangle:../export/partition-time.ts
|
|
16
16
|
* import { fromInterval, trace } from "@thi.ng/rstream";
|
|
17
|
+
* import { partitionTime } from "@thi.ng/transducers";
|
|
17
18
|
*
|
|
18
|
-
* // stream emits
|
|
19
|
+
* // stream emits counter value every 250ms
|
|
20
|
+
* // callect & partition into tuples every 1000ms
|
|
19
21
|
* fromInterval(250)
|
|
20
22
|
* .transform(partitionTime(1000))
|
|
21
23
|
* .subscribe(trace())
|
package/partition-when.d.ts
CHANGED
|
@@ -6,10 +6,12 @@ import type { Transducer } from "./api.js";
|
|
|
6
6
|
* happens yields chunk of buffered values.
|
|
7
7
|
*
|
|
8
8
|
* @example
|
|
9
|
-
* ```ts
|
|
9
|
+
* ```ts tangle:../export/partition-when.ts
|
|
10
10
|
* import { partitionWhen } from "@thi.ng/transducers";
|
|
11
11
|
*
|
|
12
|
-
*
|
|
12
|
+
* console.log(
|
|
13
|
+
* [...partitionWhen((x) => !!x, [0, 1, 0, 0, 1, 1, 0, 1])]
|
|
14
|
+
* );
|
|
13
15
|
* // [ [ 0 ], [ 1, 0, 0 ], [ 1 ], [ 1, 0 ], [ 1 ] ]
|
|
14
16
|
* ```
|
|
15
17
|
*
|
package/partition.d.ts
CHANGED
|
@@ -7,16 +7,22 @@ import type { Transducer } from "./api.js";
|
|
|
7
7
|
* be incomplete / partially filled only.
|
|
8
8
|
*
|
|
9
9
|
* @example
|
|
10
|
-
* ```ts
|
|
11
|
-
* import { partition } from "@thi.ng/transducers";
|
|
10
|
+
* ```ts tangle:../export/partition.ts
|
|
11
|
+
* import { partition, range } from "@thi.ng/transducers";
|
|
12
12
|
*
|
|
13
|
-
*
|
|
13
|
+
* console.log(
|
|
14
|
+
* [...partition(3, range(10))]
|
|
15
|
+
* );
|
|
14
16
|
* // [ [ 0, 1, 2 ], [ 3, 4, 5 ], [ 6, 7, 8 ] ]
|
|
15
17
|
*
|
|
16
|
-
*
|
|
18
|
+
* console.log(
|
|
19
|
+
* [...partition(3, true, range(10))]
|
|
20
|
+
* );
|
|
17
21
|
* // [ [ 0, 1, 2 ], [ 3, 4, 5 ], [ 6, 7, 8 ], [ 9 ] ]
|
|
18
22
|
*
|
|
19
|
-
*
|
|
23
|
+
* console.log(
|
|
24
|
+
* [...partition(3, 1, range(10))]
|
|
25
|
+
* );
|
|
20
26
|
* // [ [ 0, 1, 2 ],
|
|
21
27
|
* // [ 1, 2, 3 ],
|
|
22
28
|
* // [ 2, 3, 4 ],
|
package/peek.d.ts
CHANGED
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
import type { Transducer } from "./api.js";
|
|
2
2
|
/**
|
|
3
3
|
* Transducer version of
|
|
4
|
-
* [`peek()`](https://docs.thi.ng/umbrella/
|
|
4
|
+
* [`peek()`](https://docs.thi.ng/umbrella/arrays/functions/peek.html), i.e.
|
|
5
5
|
* extracts the last item of an array.
|
|
6
6
|
*
|
|
7
7
|
* @example
|
|
8
|
-
* ```ts
|
|
8
|
+
* ```ts tangle:../export/peek.ts
|
|
9
9
|
* import { peek } from "@thi.ng/transducers";
|
|
10
10
|
*
|
|
11
|
-
*
|
|
11
|
+
* console.log(
|
|
12
|
+
* [...peek([ [1, 2, 3], [4, 5] ])]
|
|
13
|
+
* );
|
|
12
14
|
* // [ 3, 5 ]
|
|
13
15
|
* ```
|
|
14
16
|
*/
|
package/permutations.d.ts
CHANGED
|
@@ -6,17 +6,23 @@
|
|
|
6
6
|
* empty the iterator yields no values.
|
|
7
7
|
*
|
|
8
8
|
* @example
|
|
9
|
-
* ```ts
|
|
10
|
-
* import { permutations } from "@thi.ng/transducers";
|
|
9
|
+
* ```ts tangle:../export/permutations.ts
|
|
10
|
+
* import { map, permutations, range } from "@thi.ng/transducers";
|
|
11
11
|
*
|
|
12
|
-
*
|
|
12
|
+
* console.log(
|
|
13
|
+
* [...permutations("ab", range(3))]
|
|
14
|
+
* );
|
|
13
15
|
* // [ ['a', 0], ['a', 1], ['a', 2],
|
|
14
16
|
* // ['b', 0], ['b', 1], ['b', 2] ]
|
|
15
17
|
*
|
|
16
|
-
*
|
|
18
|
+
* console.log(
|
|
19
|
+
* [...map((x: any[]) => x.join(""), permutations("ab", "-", range(3)))]
|
|
20
|
+
* );
|
|
17
21
|
* // ['a-0', 'a-1', 'a-2', 'b-0', 'b-1', 'b-2']
|
|
18
22
|
*
|
|
19
|
-
*
|
|
23
|
+
* console.log(
|
|
24
|
+
* [...permutations([], "", range(0))]
|
|
25
|
+
* );
|
|
20
26
|
* // []
|
|
21
27
|
* ```
|
|
22
28
|
*
|
|
@@ -37,18 +43,24 @@ export declare function permutations(...src: Iterable<any>[]): IterableIterator<
|
|
|
37
43
|
* values for each dimension.
|
|
38
44
|
*
|
|
39
45
|
* @example
|
|
40
|
-
* ```ts
|
|
46
|
+
* ```ts tangle:../export/permutations-n.ts
|
|
41
47
|
* import { permutationsN } from "@thi.ng/transducers";
|
|
42
48
|
*
|
|
43
|
-
*
|
|
49
|
+
* console.log(
|
|
50
|
+
* [...permutationsN(2)]
|
|
51
|
+
* );
|
|
44
52
|
* // [ [0, 0], [0, 1], [1, 0], [1, 1] ]
|
|
45
53
|
*
|
|
46
|
-
*
|
|
54
|
+
* console.log(
|
|
55
|
+
* [...permutationsN(2, 3)]
|
|
56
|
+
* );
|
|
47
57
|
* // [ [0, 0], [0, 1], [0, 2],
|
|
48
58
|
* // [1, 0], [1, 1], [1, 2],
|
|
49
59
|
* // [2, 0], [2, 1], [2, 2] ]
|
|
50
60
|
*
|
|
51
|
-
*
|
|
61
|
+
* console.log(
|
|
62
|
+
* [...permutationsN(2, 2, [10, 20])]
|
|
63
|
+
* );
|
|
52
64
|
* // [ [ 10, 20 ], [ 10, 21 ], [ 11, 20 ], [ 11, 21 ] ]
|
|
53
65
|
* ```
|
|
54
66
|
*
|
package/pluck.d.ts
CHANGED
|
@@ -4,10 +4,12 @@ import type { Transducer } from "./api.js";
|
|
|
4
4
|
* sequence of these values.
|
|
5
5
|
*
|
|
6
6
|
* @example
|
|
7
|
-
* ```ts
|
|
7
|
+
* ```ts tangle:../export/pluck.ts
|
|
8
8
|
* import { pluck } from "@thi.ng/transducers";
|
|
9
9
|
*
|
|
10
|
-
*
|
|
10
|
+
* console.log(
|
|
11
|
+
* [...pluck("id", [{id: 1}, {id: 2}, {}])]
|
|
12
|
+
* );
|
|
11
13
|
* // [ 1, 2, undefined ]
|
|
12
14
|
* ```
|
|
13
15
|
*
|
package/push-sort.d.ts
CHANGED
|
@@ -8,5 +8,5 @@ import type { Reducer } from "./api.js";
|
|
|
8
8
|
* @param cmp -
|
|
9
9
|
*/
|
|
10
10
|
export declare function pushSort<T>(cmp?: Comparator<T>): Reducer<T, T[]>;
|
|
11
|
-
export declare function pushSort<T>(cmp: Maybe<Comparator<T>>,
|
|
11
|
+
export declare function pushSort<T>(cmp: Maybe<Comparator<T>>, src: Iterable<T>): T[];
|
|
12
12
|
//# sourceMappingURL=push-sort.d.ts.map
|
package/push-sort.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { compare } from "@thi.ng/compare/compare";
|
|
2
|
-
function pushSort(cmp = compare,
|
|
3
|
-
return
|
|
2
|
+
function pushSort(cmp = compare, src) {
|
|
3
|
+
return src ? [...src].sort(cmp) : [
|
|
4
4
|
() => [],
|
|
5
5
|
(acc) => acc.sort(cmp),
|
|
6
6
|
(acc, x) => (acc.push(x), acc)
|
package/push.d.ts
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
import type { Reducer } from "./api.js";
|
|
2
|
+
/**
|
|
3
|
+
* Reducer which collects inputs into a new array.
|
|
4
|
+
*/
|
|
2
5
|
export declare function push<T>(): Reducer<T, T[]>;
|
|
3
|
-
export declare function push<T>(
|
|
6
|
+
export declare function push<T>(src: Iterable<T>): T[];
|
|
4
7
|
//# sourceMappingURL=push.d.ts.map
|
package/push.js
CHANGED
package/range-nd.d.ts
CHANGED
|
@@ -7,19 +7,27 @@ import type { ArrayLikeIterable } from "@thi.ng/api";
|
|
|
7
7
|
* negative values.
|
|
8
8
|
*
|
|
9
9
|
* @example
|
|
10
|
-
* ```ts
|
|
10
|
+
* ```ts tangle:../export/range-nd.ts
|
|
11
11
|
* import { rangeNd } from "@thi.ng/transducers";
|
|
12
12
|
*
|
|
13
|
-
*
|
|
13
|
+
* console.log(
|
|
14
|
+
* [...rangeNd([2])]
|
|
15
|
+
* );
|
|
14
16
|
* // [ [ 0 ], [ 1 ] ]
|
|
15
17
|
*
|
|
16
|
-
*
|
|
18
|
+
* console.log(
|
|
19
|
+
* [...rangeNd([2, -2])]
|
|
20
|
+
* );
|
|
17
21
|
* // [ [ 0, 0 ], [ 0, -1 ], [ 1, 0 ], [ 1, -1 ] ]
|
|
18
22
|
*
|
|
19
|
-
*
|
|
23
|
+
* console.log(
|
|
24
|
+
* [...rangeNd([-1,2], [1,3])]
|
|
25
|
+
* );
|
|
20
26
|
* // [ [ -1, 2 ], [ -1, 3 ], [ 0, 2 ], [ 0, 3 ] ]
|
|
21
27
|
*
|
|
22
|
-
*
|
|
28
|
+
* console.log(
|
|
29
|
+
* [...rangeNd([2, 2, 2])]
|
|
30
|
+
* );
|
|
23
31
|
* // [
|
|
24
32
|
* // [ 0, 0, 0 ],
|
|
25
33
|
* // [ 0, 0, 1 ],
|