@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/rechunk.d.ts
CHANGED
|
@@ -11,17 +11,20 @@ import type { Transducer } from "./api.js";
|
|
|
11
11
|
* NodeJS' stream processing.
|
|
12
12
|
*
|
|
13
13
|
* @example
|
|
14
|
-
* ```ts
|
|
14
|
+
* ```ts tangle:../export/rechunk.ts
|
|
15
15
|
* import { rechunk } from "@thi.ng/transducers";
|
|
16
16
|
*
|
|
17
|
-
*
|
|
17
|
+
* console.log(
|
|
18
|
+
* [...rechunk(/-/, ["abc-d", "ef-g-", "hij", "-k-lm"])]
|
|
19
|
+
* );
|
|
18
20
|
* // [ "abc", "def", "g", "hij", "k", "lm" ]
|
|
19
21
|
* ```
|
|
20
22
|
*
|
|
21
23
|
* @example
|
|
22
|
-
* ```ts
|
|
23
|
-
* import { spawn } from "node:child_process"
|
|
24
|
+
* ```ts tangle:../export/rechunk-2.ts
|
|
24
25
|
* import { fromNodeJS, trace } from "@thi.ng/rstream";
|
|
26
|
+
* import { rechunk } from "@thi.ng/transducers";
|
|
27
|
+
* import { spawn } from "node:child_process"
|
|
25
28
|
*
|
|
26
29
|
* const cmd = spawn("ls", ["-la"]);
|
|
27
30
|
*
|
|
@@ -44,6 +47,6 @@ import type { Transducer } from "./api.js";
|
|
|
44
47
|
* @param re -
|
|
45
48
|
*/
|
|
46
49
|
export declare function rechunk(re?: RegExp): Transducer<string, string>;
|
|
47
|
-
export declare function rechunk(
|
|
48
|
-
export declare function rechunk(re: RegExp,
|
|
50
|
+
export declare function rechunk(src: Iterable<string>): IterableIterator<string>;
|
|
51
|
+
export declare function rechunk(re: RegExp, src: Iterable<string>): IterableIterator<string>;
|
|
49
52
|
//# sourceMappingURL=rechunk.d.ts.map
|
package/reduce.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import type { Fn0, FnAny } from "@thi.ng/api";
|
|
2
2
|
import type { IReducible, Reducer, ReductionFn } from "./api.js";
|
|
3
|
-
export declare function reduce<A, B>(rfn: Reducer<A, B>,
|
|
4
|
-
export declare function reduce<A, B>(rfn: Reducer<A, B>, acc: B,
|
|
5
|
-
export declare function reduce<A, B>(rfn: Reducer<A, B>,
|
|
6
|
-
export declare function reduce<A, B>(rfn: Reducer<A, B>, acc: A,
|
|
7
|
-
export declare function reduceRight<A, B>(rfn: Reducer<A, B>,
|
|
8
|
-
export declare function reduceRight<A, B>(rfn: Reducer<A, B>, acc: B,
|
|
3
|
+
export declare function reduce<A, B>(rfn: Reducer<A, B>, src: Iterable<A>): B;
|
|
4
|
+
export declare function reduce<A, B>(rfn: Reducer<A, B>, acc: B, src: Iterable<A>): B;
|
|
5
|
+
export declare function reduce<A, B>(rfn: Reducer<A, B>, src: IReducible<A, B>): B;
|
|
6
|
+
export declare function reduce<A, B>(rfn: Reducer<A, B>, acc: A, src: IReducible<A, B>): B;
|
|
7
|
+
export declare function reduceRight<A, B>(rfn: Reducer<A, B>, src: ArrayLike<A>): B;
|
|
8
|
+
export declare function reduceRight<A, B>(rfn: Reducer<A, B>, acc: B, src: ArrayLike<A>): B;
|
|
9
9
|
/**
|
|
10
10
|
* Convenience helper for building a full {@link Reducer} using the identity
|
|
11
11
|
* function (i.e. `(x) => x`) as completion step (true for 90% of all
|
package/reduce.js
CHANGED
|
@@ -4,28 +4,28 @@ import { isArrayLike } from "@thi.ng/checks/is-arraylike";
|
|
|
4
4
|
import { isIterable } from "@thi.ng/checks/is-iterable";
|
|
5
5
|
import { illegalArity } from "@thi.ng/errors/illegal-arity";
|
|
6
6
|
import { isReduced, unreduced } from "./reduced.js";
|
|
7
|
-
const
|
|
7
|
+
const __parseArgs = (args) => args.length === 2 ? [void 0, args[1]] : args.length === 3 ? [args[1], args[2]] : illegalArity(args.length);
|
|
8
8
|
function reduce(...args) {
|
|
9
9
|
const rfn = args[0];
|
|
10
10
|
const init = rfn[0];
|
|
11
11
|
const complete = rfn[1];
|
|
12
12
|
const reduce2 = rfn[2];
|
|
13
|
-
args =
|
|
13
|
+
args = __parseArgs(args);
|
|
14
14
|
const acc = args[0] == null ? init() : args[0];
|
|
15
|
-
const
|
|
15
|
+
const src = args[1];
|
|
16
16
|
return unreduced(
|
|
17
17
|
complete(
|
|
18
|
-
implementsFunction(
|
|
18
|
+
implementsFunction(src, "$reduce") ? src.$reduce(reduce2, acc) : isArrayLike(src) ? __reduceArray(reduce2, acc, src) : __reduceIterable(reduce2, acc, src)
|
|
19
19
|
)
|
|
20
20
|
);
|
|
21
21
|
}
|
|
22
22
|
function reduceRight(...args) {
|
|
23
23
|
const [init, complete, reduce2] = args[0];
|
|
24
|
-
args =
|
|
24
|
+
args = __parseArgs(args);
|
|
25
25
|
let acc = args[0] == null ? init() : args[0];
|
|
26
|
-
const
|
|
27
|
-
for (let i =
|
|
28
|
-
acc = reduce2(acc,
|
|
26
|
+
const src = args[1];
|
|
27
|
+
for (let i = src.length; i-- > 0; ) {
|
|
28
|
+
acc = reduce2(acc, src[i]);
|
|
29
29
|
if (isReduced(acc)) {
|
|
30
30
|
acc = acc.deref();
|
|
31
31
|
break;
|
|
@@ -33,9 +33,9 @@ function reduceRight(...args) {
|
|
|
33
33
|
}
|
|
34
34
|
return unreduced(complete(acc));
|
|
35
35
|
}
|
|
36
|
-
const
|
|
37
|
-
for (let i = 0, n =
|
|
38
|
-
acc = rfn(acc,
|
|
36
|
+
const __reduceArray = (rfn, acc, src) => {
|
|
37
|
+
for (let i = 0, n = src.length; i < n; i++) {
|
|
38
|
+
acc = rfn(acc, src[i]);
|
|
39
39
|
if (isReduced(acc)) {
|
|
40
40
|
acc = acc.deref();
|
|
41
41
|
break;
|
|
@@ -43,8 +43,8 @@ const reduceArray = (rfn, acc, xs) => {
|
|
|
43
43
|
}
|
|
44
44
|
return acc;
|
|
45
45
|
};
|
|
46
|
-
const
|
|
47
|
-
for (let x of
|
|
46
|
+
const __reduceIterable = (rfn, acc, src) => {
|
|
47
|
+
for (let x of src) {
|
|
48
48
|
acc = rfn(acc, x);
|
|
49
49
|
if (isReduced(acc)) {
|
|
50
50
|
acc = acc.deref();
|
package/reductions.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import type { Reducer } from "./api.js";
|
|
2
2
|
export declare function reductions<A, B>(rfn: Reducer<A, B>): Reducer<A, B[]>;
|
|
3
|
-
export declare function reductions<A, B>(rfn: Reducer<A, B>,
|
|
3
|
+
export declare function reductions<A, B>(rfn: Reducer<A, B>, src: Iterable<A>): B[];
|
|
4
4
|
//# sourceMappingURL=reductions.d.ts.map
|
package/reductions.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { reduce } from "./reduce.js";
|
|
2
2
|
import { isReduced, reduced } from "./reduced.js";
|
|
3
|
-
function reductions(rfn,
|
|
3
|
+
function reductions(rfn, src) {
|
|
4
4
|
const [init, complete, _reduce] = rfn;
|
|
5
|
-
return
|
|
5
|
+
return src ? reduce(reductions(rfn), src) : [
|
|
6
6
|
() => [init()],
|
|
7
7
|
(acc) => (acc[acc.length - 1] = complete(acc[acc.length - 1]), acc),
|
|
8
8
|
(acc, x) => {
|
package/repeat.d.ts
CHANGED
|
@@ -5,10 +5,12 @@
|
|
|
5
5
|
* See also: {@link repeatedly}
|
|
6
6
|
*
|
|
7
7
|
* @example
|
|
8
|
-
* ```ts
|
|
8
|
+
* ```ts tangle:../export/repeat.ts
|
|
9
9
|
* import { repeat } from "@thi.ng/transducers";
|
|
10
10
|
*
|
|
11
|
-
*
|
|
11
|
+
* console.log(
|
|
12
|
+
* [...repeat(42, 5)]
|
|
13
|
+
* );
|
|
12
14
|
* // [42, 42, 42, 42, 42]
|
|
13
15
|
* ```
|
|
14
16
|
*
|
package/repeatedly.d.ts
CHANGED
|
@@ -5,14 +5,18 @@ import type { Fn } from "@thi.ng/api";
|
|
|
5
5
|
* will be produced, else the iterator is infinite.
|
|
6
6
|
*
|
|
7
7
|
* @example
|
|
8
|
-
* ```ts
|
|
8
|
+
* ```ts tangle:../export/repeatedly.ts
|
|
9
9
|
* import { repeatedly } from "@thi.ng/transducers";
|
|
10
10
|
*
|
|
11
|
-
*
|
|
11
|
+
* console.log(
|
|
12
|
+
* [...repeatedly(() => Math.floor(Math.random() * 10), 5)]
|
|
13
|
+
* );
|
|
12
14
|
* // [7, 0, 9, 3, 1]
|
|
13
15
|
*
|
|
14
16
|
* // same result as range(5)
|
|
15
|
-
*
|
|
17
|
+
* console.log(
|
|
18
|
+
* [...repeatedly((i) => i, 5)]
|
|
19
|
+
* );
|
|
16
20
|
* // [0, 1, 2, 3, 4]
|
|
17
21
|
* ```
|
|
18
22
|
*
|
package/repeatedly2d.d.ts
CHANGED
|
@@ -5,10 +5,12 @@ import type { FnU2 } from "@thi.ng/api";
|
|
|
5
5
|
* `y` grid coordinates. The iteration order is always row-major.
|
|
6
6
|
*
|
|
7
7
|
* @example
|
|
8
|
-
* ```ts
|
|
8
|
+
* ```ts tangle:../export/repeatedly2d.ts
|
|
9
9
|
* import { repeatedly2d } from "@thi.ng/transducers";
|
|
10
10
|
*
|
|
11
|
-
*
|
|
11
|
+
* console.log(
|
|
12
|
+
* [...repeatedly2d((x, y) => [(x + 1) * 10, (y + 1) * 100], 2, 3)]
|
|
13
|
+
* );
|
|
12
14
|
* // [
|
|
13
15
|
* // [ 10, 100 ], [ 20, 100 ],
|
|
14
16
|
* // [ 10, 200 ], [ 20, 200 ],
|
package/repeatedly3d.d.ts
CHANGED
|
@@ -5,10 +5,12 @@ import type { FnU3 } from "@thi.ng/api";
|
|
|
5
5
|
* `z` grid coordinates. The iteration order is always slice major, then row-major.
|
|
6
6
|
*
|
|
7
7
|
* @example
|
|
8
|
-
* ```ts
|
|
8
|
+
* ```ts tangle:../export/repeatedly3d.ts
|
|
9
9
|
* import { repeatedly3d } from "@thi.ng/transducers";
|
|
10
10
|
*
|
|
11
|
-
*
|
|
11
|
+
* console.log(
|
|
12
|
+
* [...repeatedly3d((x, y, z) => [(x+1)*10, (y+1)*100, (z+1)*1000], 2, 2, 2)]
|
|
13
|
+
* );
|
|
12
14
|
* // [
|
|
13
15
|
* // [ 10, 100, 1000 ], [ 20, 100, 1000 ], [ 10, 200, 1000 ], [ 20, 200, 1000 ],
|
|
14
16
|
* // [ 10, 100, 2000 ], [ 20, 100, 2000 ], [ 10, 200, 2000 ], [ 20, 200, 2000 ]
|
package/reverse.d.ts
CHANGED
|
@@ -3,10 +3,12 @@
|
|
|
3
3
|
* order. Important: Input MUST be finite.
|
|
4
4
|
*
|
|
5
5
|
* @example
|
|
6
|
-
* ```ts
|
|
6
|
+
* ```ts tangle:../export/reverse.ts
|
|
7
7
|
* import { reverse } from "@thi.ng/transducers";
|
|
8
8
|
*
|
|
9
|
-
*
|
|
9
|
+
* console.log(
|
|
10
|
+
* [...reverse("hello world")]
|
|
11
|
+
* );
|
|
10
12
|
* // [ "d", "l", "r", "o", "w", " ", "o", "l", "l", "e", "h" ]
|
|
11
13
|
* ```
|
|
12
14
|
*
|
package/run.d.ts
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
import type { Fn } from "@thi.ng/api";
|
|
2
2
|
import type { IReducible, TxLike } from "./api.js";
|
|
3
3
|
/**
|
|
4
|
-
* Transforms `
|
|
5
|
-
* without any reduction step. If `fx` is given it will be called with
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
4
|
+
* Transforms `src` with given transducer `tx` and optional side-effect `fx`
|
|
5
|
+
* without any reduction step. If `fx` is given it will be called with every
|
|
6
|
+
* value produced by the transducer. If `fx` is *not* given, the transducer is
|
|
7
|
+
* assumed to include at least one {@link sideEffect} step itself. Returns
|
|
8
|
+
* nothing.
|
|
9
9
|
*
|
|
10
10
|
* @param tx -
|
|
11
|
-
* @param
|
|
11
|
+
* @param src -
|
|
12
12
|
*/
|
|
13
|
-
export declare function run<A>(tx: TxLike<A, any>,
|
|
14
|
-
export declare function run<A>(tx: TxLike<A, any>,
|
|
15
|
-
export declare function run<A, B>(tx: TxLike<A, B>, fx: Fn<B, void>,
|
|
16
|
-
export declare function run<A, B>(tx: TxLike<A, B>, fx: Fn<B, void>,
|
|
13
|
+
export declare function run<A>(tx: TxLike<A, any>, src: Iterable<A>): void;
|
|
14
|
+
export declare function run<A>(tx: TxLike<A, any>, src: IReducible<A, any>): void;
|
|
15
|
+
export declare function run<A, B>(tx: TxLike<A, B>, fx: Fn<B, void>, src: Iterable<A>): void;
|
|
16
|
+
export declare function run<A, B>(tx: TxLike<A, B>, fx: Fn<B, void>, src: IReducible<A, any>): void;
|
|
17
17
|
//# sourceMappingURL=run.d.ts.map
|
package/sample.d.ts
CHANGED
|
@@ -6,11 +6,13 @@ import type { Transducer } from "./api.js";
|
|
|
6
6
|
* [`IRandom`](https://docs.thi.ng/umbrella/random/interfaces/IRandom.html) interface.
|
|
7
7
|
*
|
|
8
8
|
* @example
|
|
9
|
-
* ```ts
|
|
9
|
+
* ```ts tangle:../export/sample.ts
|
|
10
10
|
* import { range, sample } from "@thi.ng/transducers";
|
|
11
11
|
*
|
|
12
12
|
* // 10% probability
|
|
13
|
-
*
|
|
13
|
+
* console.log(
|
|
14
|
+
* [...sample(0.1, range(100))]
|
|
15
|
+
* );
|
|
14
16
|
* // [ 3, 24, 25, 36, 43, 49, 59, 64, 82, 86, 89 ]
|
|
15
17
|
* ```
|
|
16
18
|
*
|
package/scan.d.ts
CHANGED
|
@@ -11,33 +11,37 @@ import type { Reducer, Transducer } from "./api.js";
|
|
|
11
11
|
* https://en.wikipedia.org/wiki/Prefix_sum#Scan_higher_order_function
|
|
12
12
|
*
|
|
13
13
|
* @example
|
|
14
|
-
* ```ts
|
|
15
|
-
* import
|
|
16
|
-
* add, comp, last, length, multiplex, range, scan, transduce
|
|
17
|
-
* } from "@thi.ng/transducers";
|
|
14
|
+
* ```ts tangle:../export/scan.ts
|
|
15
|
+
* import * as tx from "@thi.ng/transducers";
|
|
18
16
|
*
|
|
19
|
-
*
|
|
17
|
+
* console.log(
|
|
18
|
+
* [...tx.iterator(tx.scan(tx.add()), tx.range(10))]
|
|
19
|
+
* );
|
|
20
20
|
* // [ 0, 1, 3, 6, 10, 15, 21, 28, 36, 45 ]
|
|
21
21
|
*
|
|
22
22
|
* // directly as iterator and with initial result
|
|
23
|
-
*
|
|
23
|
+
* console.log(
|
|
24
|
+
* [...tx.scan(tx.add(), 100, tx.range(10))]
|
|
25
|
+
* );
|
|
24
26
|
* // [ 100, 101, 103, 106, 110, 115, 121, 128, 136, 145 ]
|
|
25
27
|
*
|
|
26
28
|
* // as transducer
|
|
27
|
-
* transduce(
|
|
29
|
+
* const res = tx.transduce(
|
|
28
30
|
* // parallel processing lanes for each input
|
|
29
|
-
* multiplex(
|
|
30
|
-
* // join strings
|
|
31
|
-
* scan(str(" ")),
|
|
32
|
-
* // compute total length (+1)
|
|
33
|
-
* comp(length(1), scan(add()))
|
|
31
|
+
* tx.multiplex(
|
|
32
|
+
* // first lane: join strings
|
|
33
|
+
* tx.scan(tx.str(" ")),
|
|
34
|
+
* // second lane: compute total length (+1)
|
|
35
|
+
* tx.comp(tx.length(1), tx.scan(tx.add()))
|
|
34
36
|
* ),
|
|
35
|
-
* // only keep final value
|
|
36
|
-
* last(),
|
|
37
|
+
* // use last() reducer to only keep final value
|
|
38
|
+
* tx.last(),
|
|
37
39
|
* // inputs
|
|
38
40
|
* ["alpha", "beta", "gamma", "delta"]
|
|
39
|
-
* )
|
|
40
|
-
*
|
|
41
|
+
* );
|
|
42
|
+
*
|
|
43
|
+
* console.log(res);
|
|
44
|
+
* // [ 'alpha beta gamma delta', 123 ]
|
|
41
45
|
* ```
|
|
42
46
|
*
|
|
43
47
|
* @param rfn - reducer used as scan operator
|
package/select-keys.d.ts
CHANGED
|
@@ -8,17 +8,19 @@ import type { Transducer } from "./api.js";
|
|
|
8
8
|
* For single key extraction {@link pluck} is a faster alternative.
|
|
9
9
|
*
|
|
10
10
|
* @example
|
|
11
|
-
* ```ts
|
|
11
|
+
* ```ts tangle:../export/select-keys.ts
|
|
12
12
|
* import { selectKeys } from "@thi.ng/transducers";
|
|
13
13
|
*
|
|
14
|
-
* [...selectKeys(
|
|
14
|
+
* const res = [...selectKeys(
|
|
15
15
|
* ["id", "age"],
|
|
16
16
|
* [
|
|
17
17
|
* {id: 1, age: 23, name: "alice"},
|
|
18
18
|
* {id: 2, age: 42, name: "bob"},
|
|
19
19
|
* {id: 3, name: "charlie"},
|
|
20
20
|
* ]
|
|
21
|
-
* )]
|
|
21
|
+
* )];
|
|
22
|
+
*
|
|
23
|
+
* console.log(res);
|
|
22
24
|
* // [ { age: 23, id: 1 }, { age: 42, id: 2 }, { id: 3 } ]
|
|
23
25
|
* ```
|
|
24
26
|
*
|
package/sliding-window.d.ts
CHANGED
|
@@ -11,14 +11,20 @@ import type { Transducer } from "./api.js";
|
|
|
11
11
|
* window size will be re-evaluated for each new input and therefore can be used
|
|
12
12
|
* as mechanism to dynamically adjust the window size.
|
|
13
13
|
*
|
|
14
|
+
* Also see {@link partition}.
|
|
15
|
+
*
|
|
14
16
|
* @example
|
|
15
|
-
* ```ts
|
|
17
|
+
* ```ts tangle:../export/sliding-window.ts
|
|
16
18
|
* import { range, slidingWindow } from "@thi.ng/transducers";
|
|
17
19
|
*
|
|
18
|
-
*
|
|
20
|
+
* console.log(
|
|
21
|
+
* [...slidingWindow(3, range(5))]
|
|
22
|
+
* );
|
|
19
23
|
* // [ [ 0 ], [ 0, 1 ], [ 0, 1, 2 ], [ 1, 2, 3 ], [ 2, 3, 4 ] ]
|
|
20
24
|
*
|
|
21
|
-
*
|
|
25
|
+
* console.log(
|
|
26
|
+
* [...slidingWindow(3, false, range(5))]
|
|
27
|
+
* );
|
|
22
28
|
* // [ [ 0, 1, 2 ], [ 1, 2, 3 ], [ 2, 3, 4 ] ]
|
|
23
29
|
* ```
|
|
24
30
|
*
|
package/some.d.ts
CHANGED
|
@@ -8,6 +8,6 @@ import type { Reducer } from "./api.js";
|
|
|
8
8
|
* @param pred -
|
|
9
9
|
*/
|
|
10
10
|
export declare function some<T>(pred?: Predicate<T>): Reducer<T, boolean>;
|
|
11
|
-
export declare function some<T>(
|
|
12
|
-
export declare function some<T>(pred: Predicate<T>,
|
|
11
|
+
export declare function some<T>(src: Iterable<T>): boolean;
|
|
12
|
+
export declare function some<T>(pred: Predicate<T>, src: Iterable<T>): boolean;
|
|
13
13
|
//# sourceMappingURL=some.d.ts.map
|
package/step.d.ts
CHANGED
|
@@ -11,41 +11,56 @@ import type { TxLike } from "./api.js";
|
|
|
11
11
|
* invocations of the stepper function will return undefined.
|
|
12
12
|
*
|
|
13
13
|
* @example
|
|
14
|
-
* ```ts
|
|
15
|
-
* import { filter, map,
|
|
14
|
+
* ```ts tangle:../export/step.ts
|
|
15
|
+
* import { filter, map, mapcat, step, take } from "@thi.ng/transducers";
|
|
16
16
|
*
|
|
17
17
|
* // single result (unwrapped, default)
|
|
18
|
-
*
|
|
18
|
+
* console.log(
|
|
19
|
+
* step(map((x: number) => x * 10))(1)
|
|
20
|
+
* );
|
|
19
21
|
* // 10
|
|
20
22
|
*
|
|
21
23
|
* // single result (no unwrapping)
|
|
22
|
-
*
|
|
24
|
+
* console.log(
|
|
25
|
+
* step(map((x: number) => x * 10), false)(1)
|
|
26
|
+
* );
|
|
23
27
|
* // [10]
|
|
24
28
|
*
|
|
25
29
|
* // multiple results
|
|
26
|
-
*
|
|
30
|
+
* console.log(
|
|
31
|
+
* step(mapcat((x: number) => [x, x + 1, x + 2]))(1)
|
|
32
|
+
* );
|
|
27
33
|
* // [ 1, 2, 3 ]
|
|
28
34
|
*
|
|
29
35
|
* // multiple results (default behavior)
|
|
30
|
-
*
|
|
36
|
+
* console.log(
|
|
37
|
+
* step(mapcat((x: number[]) => take(2, x)))([1, 2, 3, 4])
|
|
38
|
+
* );
|
|
31
39
|
* // [1, 2]
|
|
32
|
-
*
|
|
40
|
+
*
|
|
41
|
+
* console.log(
|
|
42
|
+
* step(mapcat((x: number[]) => x))([3])
|
|
43
|
+
* );
|
|
33
44
|
* // 3
|
|
45
|
+
*
|
|
34
46
|
* // ...once more without unwrapping
|
|
35
|
-
*
|
|
47
|
+
* console.log(
|
|
48
|
+
* step(mapcat((x: number[]) => x), false)([3])
|
|
49
|
+
* );
|
|
36
50
|
* // [3]
|
|
37
51
|
*
|
|
38
|
-
* //
|
|
39
|
-
* f = step(filter((x) => !(x & 1)))
|
|
40
|
-
*
|
|
41
|
-
* f(
|
|
52
|
+
* // filter even values
|
|
53
|
+
* const f = step(filter((x: number) => !(x & 1)))
|
|
54
|
+
*
|
|
55
|
+
* console.log(f(1)); // undefined
|
|
56
|
+
* console.log(f(2)); // 2
|
|
42
57
|
*
|
|
43
58
|
* // reduced value termination
|
|
44
|
-
*
|
|
45
|
-
*
|
|
46
|
-
*
|
|
47
|
-
*
|
|
48
|
-
*
|
|
59
|
+
* const g = step(take(2));
|
|
60
|
+
* console.log(g(1)); // 1
|
|
61
|
+
* console.log(g(1)); // 1
|
|
62
|
+
* console.log(g(1)); // undefined
|
|
63
|
+
* console.log(g(1)); // undefined
|
|
49
64
|
* ```
|
|
50
65
|
*
|
|
51
66
|
* @param tx -
|
package/str.d.ts
CHANGED
|
@@ -1,4 +1,10 @@
|
|
|
1
1
|
import type { Reducer } from "./api.js";
|
|
2
|
+
/**
|
|
3
|
+
* Reducer which concatenates inputs into a string, each value separated by
|
|
4
|
+
* `sep` (default: "").
|
|
5
|
+
*
|
|
6
|
+
* @param sep
|
|
7
|
+
*/
|
|
2
8
|
export declare function str(sep?: string): Reducer<any, string>;
|
|
3
|
-
export declare function str(sep: string,
|
|
9
|
+
export declare function str(sep: string, src: Iterable<any>): string;
|
|
4
10
|
//# sourceMappingURL=str.d.ts.map
|
package/str.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { reducer } from "./reduce.js";
|
|
2
|
-
function str(sep,
|
|
2
|
+
function str(sep, src) {
|
|
3
3
|
sep = sep || "";
|
|
4
4
|
let first = true;
|
|
5
|
-
return
|
|
5
|
+
return src ? [...src].join(sep) : reducer(
|
|
6
6
|
() => "",
|
|
7
7
|
(acc, x) => (acc = first ? acc + x : acc + sep + x, first = false, acc)
|
|
8
8
|
);
|
package/stream-shuffle.d.ts
CHANGED
|
@@ -26,14 +26,18 @@ export interface StreamShuffleOpts {
|
|
|
26
26
|
* are possible.
|
|
27
27
|
*
|
|
28
28
|
* @example
|
|
29
|
-
* ```ts
|
|
29
|
+
* ```ts tangle:../export/stream-shuffle.ts
|
|
30
30
|
* import { range, streamShuffle } from "@thi.ng/transducers";
|
|
31
31
|
* import { XsAdd } from "@thi.ng/random";
|
|
32
32
|
*
|
|
33
|
-
*
|
|
33
|
+
* console.log(
|
|
34
|
+
* [...streamShuffle(5, range(10))]
|
|
35
|
+
* );
|
|
34
36
|
* // [ 3, 2, 5, 0, 8, 7, 1, 6, 4, 9 ]
|
|
35
37
|
*
|
|
36
|
-
*
|
|
38
|
+
* console.log(
|
|
39
|
+
* [...streamShuffle({ n: 5, rnd: new XsAdd(12345) }, range(10))]
|
|
40
|
+
* );
|
|
37
41
|
* [ 0, 4, 3, 7, 8, 1, 5, 2, 6, 9 ]
|
|
38
42
|
* ```
|
|
39
43
|
*
|
package/stream-sort.d.ts
CHANGED
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
import type { SortOpts, Transducer } from "./api.js";
|
|
2
2
|
/**
|
|
3
|
-
* Transducer. Similar to {@link partitionSort}, however uses
|
|
4
|
-
*
|
|
3
|
+
* Transducer. Similar to {@link partitionSort}, however uses a sliding window
|
|
4
|
+
* of size `n` and insertion sort instead of fully sorting window as done by
|
|
5
5
|
* `partitionSort`.
|
|
6
6
|
*
|
|
7
7
|
* @example
|
|
8
|
-
* ```ts
|
|
8
|
+
* ```ts tangle:../export/stream-sort.ts
|
|
9
9
|
* import { streamSort } from "@thi.ng/transducers";
|
|
10
10
|
*
|
|
11
|
-
*
|
|
11
|
+
* console.log(
|
|
12
|
+
* [...streamSort(4, [5,9,2,6,4,1,3,8,7,0])]
|
|
13
|
+
* );
|
|
12
14
|
* // [ 2, 4, 1, 3, 5, 6, 0, 7, 8, 9 ]
|
|
13
15
|
* ```
|
|
14
16
|
*
|
package/struct.d.ts
CHANGED
|
@@ -18,22 +18,29 @@ export type StructField<T> = [string, number, Fn<T[], any>?];
|
|
|
18
18
|
* field values, e.g. from `[123] => 123`
|
|
19
19
|
*
|
|
20
20
|
* @example
|
|
21
|
-
* ```ts
|
|
21
|
+
* ```ts tangle:../export/struct.ts
|
|
22
22
|
* import { push, struct, transduce } from "@thi.ng/transducers";
|
|
23
23
|
*
|
|
24
|
-
* transduce(
|
|
24
|
+
* const res = transduce(
|
|
25
25
|
* struct([["id", 1, (id) => id[0]], ["pos", 2], ["vel", 2], ["color", 4]]),
|
|
26
26
|
* push(),
|
|
27
27
|
* [0, 100, 200, -1, 0, 1, 0.5, 0, 1, 1, 0, 0, 5, 4, 0, 0, 1, 1]
|
|
28
|
-
* )
|
|
29
|
-
*
|
|
28
|
+
* );
|
|
29
|
+
*
|
|
30
|
+
* console.log(res);
|
|
31
|
+
* // [
|
|
32
|
+
* // {
|
|
33
|
+
* // color: [ 1, 0.5, 0, 1 ],
|
|
30
34
|
* // vel: [ -1, 0 ],
|
|
31
35
|
* // pos: [ 100, 200 ],
|
|
32
|
-
* // id: 0
|
|
33
|
-
* //
|
|
36
|
+
* // id: 0,
|
|
37
|
+
* // }, {
|
|
38
|
+
* // color: [ 0, 0, 1, 1 ],
|
|
34
39
|
* // vel: [ 5, 4 ],
|
|
35
40
|
* // pos: [ 0, 0 ],
|
|
36
|
-
* // id: 1
|
|
41
|
+
* // id: 1,
|
|
42
|
+
* // }
|
|
43
|
+
* // ]
|
|
37
44
|
* ```
|
|
38
45
|
*
|
|
39
46
|
* @param fields -
|
package/sub.d.ts
CHANGED
|
@@ -4,6 +4,6 @@ import type { Reducer } from "./api.js";
|
|
|
4
4
|
* (default: 0).
|
|
5
5
|
*/
|
|
6
6
|
export declare function sub(init?: number): Reducer<number, number>;
|
|
7
|
-
export declare function sub(
|
|
8
|
-
export declare function sub(init: number,
|
|
7
|
+
export declare function sub(src: Iterable<number>): number;
|
|
8
|
+
export declare function sub(init: number, src: Iterable<number>): number;
|
|
9
9
|
//# sourceMappingURL=sub.d.ts.map
|
package/sub.js
CHANGED
package/swizzle.d.ts
CHANGED
|
@@ -4,16 +4,22 @@ import type { Transducer } from "./api.js";
|
|
|
4
4
|
* order. Accepts arrays or objects as input, but always yields arrays.
|
|
5
5
|
*
|
|
6
6
|
* @example
|
|
7
|
-
* ```ts
|
|
7
|
+
* ```ts tangle:../export/swizzle.ts
|
|
8
8
|
* import { swizzle } from "@thi.ng/transducers";
|
|
9
9
|
*
|
|
10
|
-
*
|
|
10
|
+
* console.log(
|
|
11
|
+
* [...swizzle([3, 0, 2, 1], [[1, 2, 3, 4], [10, 20, 30, 40]])]
|
|
12
|
+
* );
|
|
11
13
|
* // [ [ 4, 1, 3, 2 ], [ 40, 10, 30, 20 ] ]
|
|
12
14
|
*
|
|
13
|
-
*
|
|
15
|
+
* console.log(
|
|
16
|
+
* [...swizzle([0, 0, 1, 1], [[1, 2, 3, 4], [10, 20, 30, 40]])]
|
|
17
|
+
* );
|
|
14
18
|
* // [ [ 1, 1, 2, 2 ], [ 10, 10, 20, 20 ] ]
|
|
15
19
|
*
|
|
16
|
-
*
|
|
20
|
+
* console.log(
|
|
21
|
+
* [...swizzle(["z", "x"], [{x: 1, y: 2, z: 3}])]
|
|
22
|
+
* );
|
|
17
23
|
* // [ [ 3, 1 ] ]
|
|
18
24
|
* ```
|
|
19
25
|
*
|
package/symmetric.d.ts
CHANGED
|
@@ -1,13 +1,23 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Yields an iterator of all `src` values, followed by the same values in
|
|
3
3
|
* reverse order. Efficiently builds the reversed order via an internal linked
|
|
4
|
-
* list.
|
|
4
|
+
* list. The input MUST be finite!
|
|
5
|
+
*
|
|
6
|
+
* @remarks
|
|
7
|
+
* Also see {@link palindrome}.
|
|
5
8
|
*
|
|
6
9
|
* @example
|
|
7
|
-
* ```ts
|
|
10
|
+
* ```ts tangle:../export/symmetric.ts
|
|
8
11
|
* import { symmetric } from "@thi.ng/transducers";
|
|
9
12
|
*
|
|
10
|
-
*
|
|
13
|
+
* console.log(
|
|
14
|
+
* [...symmetric("abc")]
|
|
15
|
+
* );
|
|
16
|
+
* // [ "a", "b", "c", "c", "b", "a" ]
|
|
17
|
+
*
|
|
18
|
+
* console.log(
|
|
19
|
+
* [...symmetric([1, 2, 3])]
|
|
20
|
+
* );
|
|
11
21
|
* // [ 1, 2, 3, 3, 2, 1 ]
|
|
12
22
|
* ```
|
|
13
23
|
*
|
package/take-last.d.ts
CHANGED
|
@@ -4,10 +4,12 @@ import type { Transducer } from "./api.js";
|
|
|
4
4
|
* input source is finite (of course).
|
|
5
5
|
*
|
|
6
6
|
* @example
|
|
7
|
-
* ```ts
|
|
7
|
+
* ```ts tangle:../export/take-last.ts
|
|
8
8
|
* import { range, takeLast } from "@thi.ng/transducers";
|
|
9
9
|
*
|
|
10
|
-
*
|
|
10
|
+
* console.log(
|
|
11
|
+
* [...takeLast(3, range(10))]
|
|
12
|
+
* );
|
|
11
13
|
* // [ 7, 8, 9 ]
|
|
12
14
|
* ```
|
|
13
15
|
*
|