@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/lookup.d.ts
CHANGED
|
@@ -3,10 +3,12 @@
|
|
|
3
3
|
* lookup value in given array. No bounds checks are done.
|
|
4
4
|
*
|
|
5
5
|
* @example
|
|
6
|
-
* ```ts
|
|
6
|
+
* ```ts tangle:../export/lookup.ts
|
|
7
7
|
* import { lookup1d, map } from "@thi.ng/transducers";
|
|
8
8
|
*
|
|
9
|
-
*
|
|
9
|
+
* console.log(
|
|
10
|
+
* [...map(lookup1d([10, 20, 30]), [2,0,1])]
|
|
11
|
+
* );
|
|
10
12
|
* // [ 30, 10, 20 ]
|
|
11
13
|
* ```
|
|
12
14
|
*
|
|
@@ -23,10 +25,12 @@ export declare const lookup1d: <T>(src: T[]) => (i: number) => T;
|
|
|
23
25
|
* representation of 2D data (pixel buffer). No bounds checks are done.
|
|
24
26
|
*
|
|
25
27
|
* @example
|
|
26
|
-
* ```ts
|
|
28
|
+
* ```ts tangle:../export/lookup2d.ts
|
|
27
29
|
* import { lookup2d, map, range, range2d } from "@thi.ng/transducers";
|
|
28
30
|
*
|
|
29
|
-
*
|
|
31
|
+
* console.log(
|
|
32
|
+
* [...map(lookup2d([...range(9)], 3), range2d(2, -1, 0, 3))]
|
|
33
|
+
* );
|
|
30
34
|
* // [ 2, 1, 0, 5, 4, 3, 8, 7, 6 ]
|
|
31
35
|
* ```
|
|
32
36
|
*
|
package/map-indexed.d.ts
CHANGED
|
@@ -8,15 +8,13 @@ import type { Transducer } from "./api.js";
|
|
|
8
8
|
* An optional start index `offset` can be provided (default 0).
|
|
9
9
|
*
|
|
10
10
|
* @example
|
|
11
|
-
* ```ts
|
|
12
|
-
* import {
|
|
11
|
+
* ```ts tangle:../export/map-indexed.ts
|
|
12
|
+
* import { mapIndexed } from "@thi.ng/transducers";
|
|
13
13
|
*
|
|
14
|
-
*
|
|
15
|
-
* mapIndexed((i, x) => ["id" + i, x * 10], 42)
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
* )
|
|
19
|
-
* // { id42: 10, id43: 20, id44: 30 }
|
|
14
|
+
* console.log(
|
|
15
|
+
* [...mapIndexed((i, x) => ["id" + i, x * 10], 42, [1, 2, 3])]
|
|
16
|
+
* );
|
|
17
|
+
* // [ [ "id42", 10 ], [ "id43", 20 ], [ "id44", 30 ] ]
|
|
20
18
|
* ```
|
|
21
19
|
*
|
|
22
20
|
* @param fn - transformation function
|
package/map-keys.d.ts
CHANGED
|
@@ -8,16 +8,18 @@ import type { Transducer } from "./api.js";
|
|
|
8
8
|
* copy of each `x`.
|
|
9
9
|
*
|
|
10
10
|
* @example
|
|
11
|
-
* ```ts
|
|
11
|
+
* ```ts tangle:../export/map-keys.ts
|
|
12
12
|
* import { mapKeys } from "@thi.ng/transducers";
|
|
13
13
|
*
|
|
14
|
-
* [...mapKeys(
|
|
14
|
+
* const res = [...mapKeys(
|
|
15
15
|
* {
|
|
16
16
|
* a: (x) => x != null ? x * 10 : x,
|
|
17
17
|
* b: (x) => x != null ? x * 100: "n/a"
|
|
18
18
|
* },
|
|
19
19
|
* [{a: 1, b: 2}, {c: 3, d: 4}]
|
|
20
|
-
* )]
|
|
20
|
+
* )];
|
|
21
|
+
*
|
|
22
|
+
* console.log(res);
|
|
21
23
|
* // [ { a: 10, b: 200 }, { c: 3, d: 4, b: 'n/a', a: undefined } ]
|
|
22
24
|
* ```
|
|
23
25
|
*
|
package/map-nth.d.ts
CHANGED
|
@@ -9,15 +9,19 @@ import type { Transducer } from "./api.js";
|
|
|
9
9
|
* the first transformation occurs (default 0).
|
|
10
10
|
*
|
|
11
11
|
* @example
|
|
12
|
-
* ```ts
|
|
13
|
-
* import { mapNth } from "@thi.ng/transducers";
|
|
12
|
+
* ```ts tangle:../export/map-nth.ts
|
|
13
|
+
* import { mapNth, range } from "@thi.ng/transducers";
|
|
14
14
|
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
15
|
+
* console.log(
|
|
16
|
+
* [...mapNth(3, (x) => `*${x}*`, range(1, 10))]
|
|
17
|
+
* );
|
|
18
|
+
* // [ "*1*", 2, 3, "*4*", 5, 6, "*7*", 8, 9 ]
|
|
17
19
|
*
|
|
18
20
|
* // with offset
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
+
* console.log(
|
|
22
|
+
* [...mapNth(3, 5, (x) => x * 100, range(1, 10))]
|
|
23
|
+
* );
|
|
24
|
+
* // [ 1, 2, 3, 4, 5, 600, 7, 8, 900 ]
|
|
21
25
|
* ```
|
|
22
26
|
*
|
|
23
27
|
* @param n - step size
|
package/map-vals.d.ts
CHANGED
|
@@ -10,10 +10,12 @@ import type { Transducer } from "./api.js";
|
|
|
10
10
|
* object is then used as the result of this transducer.
|
|
11
11
|
*
|
|
12
12
|
* @example
|
|
13
|
-
* ```ts
|
|
13
|
+
* ```ts tangle:../export/map-vals.ts
|
|
14
14
|
* import { mapVals } from "@thi.ng/transducers";
|
|
15
15
|
*
|
|
16
|
-
*
|
|
16
|
+
* console.log(
|
|
17
|
+
* [...mapVals((x)=> x * 10, [{a: 1, b: 2}, {c: 3, d: 4}])]
|
|
18
|
+
* );
|
|
17
19
|
* // [ { a: 10, b: 20 }, { c: 30, d: 40 } ]
|
|
18
20
|
* ```
|
|
19
21
|
*
|
package/map.d.ts
CHANGED
|
@@ -5,10 +5,12 @@ import type { Transducer } from "./api.js";
|
|
|
5
5
|
* passes result downstream to next reducer.
|
|
6
6
|
*
|
|
7
7
|
* @example
|
|
8
|
-
* ```ts
|
|
8
|
+
* ```ts tangle:../export/map.ts
|
|
9
9
|
* import { map } from "@thi.ng/transducers";
|
|
10
10
|
*
|
|
11
|
-
*
|
|
11
|
+
* console.log(
|
|
12
|
+
* [...map((x) => x * 10, [1, 2, 3])]
|
|
13
|
+
* );
|
|
12
14
|
* // [ 10, 20, 30 ]
|
|
13
15
|
* ```
|
|
14
16
|
*
|
package/mapcat.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Fn, Nullable } from "@thi.ng/api";
|
|
2
|
-
import type { Transducer } from "./api.js";
|
|
2
|
+
import type { MaybeReduced, Transducer } from "./api.js";
|
|
3
3
|
/**
|
|
4
4
|
* Transducer. Similar to {@link map}, but expects the given mapping function
|
|
5
5
|
* `fn` to return an iterable result (or `null`) and then emits each value of
|
|
@@ -7,18 +7,22 @@ import type { Transducer } from "./api.js";
|
|
|
7
7
|
* be skipped / omitted.
|
|
8
8
|
*
|
|
9
9
|
* @example
|
|
10
|
-
* ```ts
|
|
10
|
+
* ```ts tangle:../export/mapcat.ts
|
|
11
11
|
* import { mapcat } from "@thi.ng/transducers";
|
|
12
12
|
*
|
|
13
|
-
*
|
|
13
|
+
* console.log(
|
|
14
|
+
* [...mapcat((x) => [x, x], [1, 2, 3])]
|
|
15
|
+
* );
|
|
14
16
|
* // [ 1, 1, 2, 2, 3, 3 ]
|
|
15
17
|
*
|
|
16
|
-
*
|
|
18
|
+
* console.log(
|
|
19
|
+
* [...mapcat((x) => x > 2 ? [x, x, x] : null, [1, 2, 3])]
|
|
20
|
+
* );
|
|
17
21
|
* // [ 3, 3, 3 ]
|
|
18
22
|
* ```
|
|
19
23
|
*
|
|
20
24
|
* @param fn - mapping function
|
|
21
25
|
*/
|
|
22
|
-
export declare function mapcat<A, B>(fn: Fn<A, Nullable<Iterable<B
|
|
23
|
-
export declare function mapcat<A, B>(fn: Fn<A, Nullable<Iterable<B
|
|
26
|
+
export declare function mapcat<A, B>(fn: Fn<A, MaybeReduced<Nullable<Iterable<B>>>>): Transducer<A, B>;
|
|
27
|
+
export declare function mapcat<A, B>(fn: Fn<A, MaybeReduced<Nullable<Iterable<B>>>>, src: Iterable<A>): IterableIterator<B>;
|
|
24
28
|
//# sourceMappingURL=mapcat.d.ts.map
|
package/match-first.d.ts
CHANGED
|
@@ -1,35 +1,34 @@
|
|
|
1
1
|
import type { Maybe, Predicate } from "@thi.ng/api";
|
|
2
2
|
import type { Transducer } from "./api.js";
|
|
3
3
|
/**
|
|
4
|
-
* Transducer
|
|
5
|
-
*
|
|
6
|
-
* @example
|
|
7
|
-
* ```ts
|
|
8
|
-
* import { comp, filter, take } from "@thi.ng/transducers";
|
|
9
|
-
*
|
|
10
|
-
* comp(filter(pred), take(1))
|
|
11
|
-
* // [Function]
|
|
12
|
-
* ```
|
|
13
|
-
*
|
|
14
|
-
* Yields none or only the first value which passed the predicate check
|
|
15
|
-
* and then causes early termination. If `src` input is given, returns
|
|
4
|
+
* Transducer. Yields none or only the first value which passed the predicate
|
|
5
|
+
* check and then causes early termination. If `src` input is given, returns
|
|
16
6
|
* first match found (or `undefined`). Also see {@link matchLast}.
|
|
17
7
|
*
|
|
8
|
+
* @remarks
|
|
9
|
+
* `matchFirst()` is syntax sugar for: `comp(filter(pred), take(1))`
|
|
10
|
+
*
|
|
18
11
|
* @example
|
|
19
|
-
* ```ts
|
|
20
|
-
* import {
|
|
12
|
+
* ```ts tangle:../export/match-first.ts
|
|
13
|
+
* import {
|
|
14
|
+
* comp, map, matchFirst, push, transduce
|
|
15
|
+
* } from "@thi.ng/transducers";
|
|
21
16
|
*
|
|
22
|
-
*
|
|
17
|
+
* console.log(
|
|
18
|
+
* matchFirst((x) => x >= 5, [3, 1, 4, 2, 6, 5])
|
|
19
|
+
* );
|
|
23
20
|
* // 6
|
|
24
21
|
*
|
|
25
|
-
* transduce(
|
|
22
|
+
* const res = transduce(
|
|
26
23
|
* comp(
|
|
27
24
|
* matchFirst((x) => x >= 5),
|
|
28
25
|
* map((x) => x * 10)
|
|
29
26
|
* ),
|
|
30
27
|
* push(),
|
|
31
28
|
* [3, 1, 4, 2, 6, 5]
|
|
32
|
-
* )
|
|
29
|
+
* );
|
|
30
|
+
*
|
|
31
|
+
* console.log(res);
|
|
33
32
|
* // [60]
|
|
34
33
|
* ```
|
|
35
34
|
*
|
package/match-last.d.ts
CHANGED
|
@@ -1,26 +1,30 @@
|
|
|
1
1
|
import type { Maybe, Predicate } from "@thi.ng/api";
|
|
2
2
|
import type { Transducer } from "./api.js";
|
|
3
3
|
/**
|
|
4
|
-
* Similar to {@link matchFirst}, but matches
|
|
5
|
-
*
|
|
6
|
-
*
|
|
4
|
+
* Similar to {@link matchFirst}, but matches only the **last** value which
|
|
5
|
+
* passed the predicate check. If `src` input is given, returns last match found
|
|
6
|
+
* (or `undefined`).
|
|
7
7
|
*
|
|
8
8
|
* @example
|
|
9
|
-
* ```ts
|
|
9
|
+
* ```ts tangle:../export/match-last.ts
|
|
10
10
|
* import { comp, map, matchLast, push, transduce } from "@thi.ng/transducers";
|
|
11
11
|
*
|
|
12
|
-
*
|
|
12
|
+
* console.log(
|
|
13
|
+
* matchLast((x) => x >= 5, [3, 1, 6, 5, 4, 2])
|
|
14
|
+
* );
|
|
13
15
|
* // 5
|
|
14
16
|
*
|
|
15
|
-
* transduce(
|
|
17
|
+
* const res = transduce(
|
|
16
18
|
* comp(
|
|
17
19
|
* matchLast((x) => x >= 5),
|
|
18
20
|
* map((x) => x * 10)
|
|
19
21
|
* ),
|
|
20
22
|
* push(),
|
|
21
23
|
* [3, 1, 6, 5, 4, 2]
|
|
22
|
-
* )
|
|
23
|
-
*
|
|
24
|
+
* );
|
|
25
|
+
*
|
|
26
|
+
* console.log(res);
|
|
27
|
+
* // [ 50 ]
|
|
24
28
|
* ```
|
|
25
29
|
*
|
|
26
30
|
* @param pred - predicate function
|
package/max-compare.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type { Comparator, Fn0 } from "@thi.ng/api";
|
|
1
|
+
import type { Comparator, Fn0, Nullable } from "@thi.ng/api";
|
|
2
2
|
import type { Reducer } from "./api.js";
|
|
3
3
|
export declare function maxCompare<T>(init: Fn0<T>, cmp?: Comparator<T>): Reducer<T, T>;
|
|
4
|
-
export declare function maxCompare<T>(init: Fn0<T>,
|
|
5
|
-
export declare function maxCompare<T>(init: Fn0<T>, cmp: Comparator<T
|
|
4
|
+
export declare function maxCompare<T>(init: Fn0<T>, src: Iterable<T>): T;
|
|
5
|
+
export declare function maxCompare<T>(init: Fn0<T>, cmp: Nullable<Comparator<T>>, src: Iterable<T>): T;
|
|
6
6
|
//# sourceMappingURL=max-compare.d.ts.map
|
package/max-compare.js
CHANGED
|
@@ -1,13 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { $$reduce, reducer } from "./reduce.js";
|
|
1
|
+
import { __compareOp } from "./internal/mathop.js";
|
|
3
2
|
function maxCompare(...args) {
|
|
4
|
-
|
|
5
|
-
if (res !== void 0) {
|
|
6
|
-
return res;
|
|
7
|
-
}
|
|
8
|
-
const init = args[0];
|
|
9
|
-
const cmp = args[1] || compare;
|
|
10
|
-
return reducer(init, (acc, x) => cmp(acc, x) >= 0 ? acc : x);
|
|
3
|
+
return __compareOp(maxCompare, args, 1);
|
|
11
4
|
}
|
|
12
5
|
export {
|
|
13
6
|
maxCompare
|
package/max-mag.d.ts
CHANGED
|
@@ -4,5 +4,5 @@ import type { Reducer } from "./api.js";
|
|
|
4
4
|
* sign.
|
|
5
5
|
*/
|
|
6
6
|
export declare function maxMag(): Reducer<number, number>;
|
|
7
|
-
export declare function maxMag(
|
|
7
|
+
export declare function maxMag(src: Iterable<number>): number;
|
|
8
8
|
//# sourceMappingURL=max-mag.d.ts.map
|
package/max-mag.js
CHANGED
package/max.d.ts
CHANGED
package/max.js
CHANGED
package/mean.d.ts
CHANGED
|
@@ -4,5 +4,5 @@ import type { Reducer } from "./api.js";
|
|
|
4
4
|
* were processed.
|
|
5
5
|
*/
|
|
6
6
|
export declare function mean(): Reducer<number, number>;
|
|
7
|
-
export declare function mean(
|
|
7
|
+
export declare function mean(src: Iterable<number>): number;
|
|
8
8
|
//# sourceMappingURL=mean.d.ts.map
|
package/mean.js
CHANGED
package/min-compare.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type { Comparator, Fn0 } from "@thi.ng/api";
|
|
1
|
+
import type { Comparator, Fn0, Nullable } from "@thi.ng/api";
|
|
2
2
|
import type { Reducer } from "./api.js";
|
|
3
3
|
export declare function minCompare<T>(init: Fn0<T>, cmp?: Comparator<T>): Reducer<T, T>;
|
|
4
|
-
export declare function minCompare<T>(init: Fn0<T>,
|
|
5
|
-
export declare function minCompare<T>(init: Fn0<T>, cmp: Comparator<T
|
|
4
|
+
export declare function minCompare<T>(init: Fn0<T>, src: Iterable<T>): T;
|
|
5
|
+
export declare function minCompare<T>(init: Fn0<T>, cmp: Nullable<Comparator<T>>, src: Iterable<T>): T;
|
|
6
6
|
//# sourceMappingURL=min-compare.d.ts.map
|
package/min-compare.js
CHANGED
|
@@ -1,13 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { $$reduce, reducer } from "./reduce.js";
|
|
1
|
+
import { __compareOp } from "./internal/mathop.js";
|
|
3
2
|
function minCompare(...args) {
|
|
4
|
-
|
|
5
|
-
if (res !== void 0) {
|
|
6
|
-
return res;
|
|
7
|
-
}
|
|
8
|
-
const init = args[0];
|
|
9
|
-
const cmp = args[1] || compare;
|
|
10
|
-
return reducer(init, (acc, x) => cmp(acc, x) <= 0 ? acc : x);
|
|
3
|
+
return __compareOp(minCompare, args, -1);
|
|
11
4
|
}
|
|
12
5
|
export {
|
|
13
6
|
minCompare
|
package/min-mag.d.ts
CHANGED
|
@@ -4,5 +4,5 @@ import type { Reducer } from "./api.js";
|
|
|
4
4
|
* sign.
|
|
5
5
|
*/
|
|
6
6
|
export declare function minMag(): Reducer<number, number>;
|
|
7
|
-
export declare function minMag(
|
|
7
|
+
export declare function minMag(src: Iterable<number>): number;
|
|
8
8
|
//# sourceMappingURL=min-mag.d.ts.map
|
package/min-mag.js
CHANGED
package/min.d.ts
CHANGED
package/min.js
CHANGED
package/mul.d.ts
CHANGED
|
@@ -4,6 +4,6 @@ import type { Reducer } from "./api.js";
|
|
|
4
4
|
* (default: 1).
|
|
5
5
|
*/
|
|
6
6
|
export declare function mul(init?: number): Reducer<number, number>;
|
|
7
|
-
export declare function mul(
|
|
8
|
-
export declare function mul(init: number,
|
|
7
|
+
export declare function mul(src: Iterable<number>): number;
|
|
8
|
+
export declare function mul(init: number, src: Iterable<number>): number;
|
|
9
9
|
//# sourceMappingURL=mul.d.ts.map
|
package/mul.js
CHANGED
package/multiplex-obj.d.ts
CHANGED
|
@@ -5,20 +5,24 @@ import type { MultiplexTxLike, Reducer, Transducer } from "./api.js";
|
|
|
5
5
|
* object of transducers and produces a result object for each input.
|
|
6
6
|
*
|
|
7
7
|
* @example
|
|
8
|
-
* ```ts
|
|
9
|
-
* import { multiplexObj } from "@thi.ng/transducers";
|
|
8
|
+
* ```ts tangle:../export/multiplex-obj.ts
|
|
9
|
+
* import { multiplexObj, map } from "@thi.ng/transducers";
|
|
10
10
|
*
|
|
11
|
-
* [...multiplexObj(
|
|
11
|
+
* const res = [...multiplexObj(
|
|
12
12
|
* {
|
|
13
13
|
* initial: map(x => x.charAt(0)),
|
|
14
14
|
* upper: map(x => x.toUpperCase()),
|
|
15
15
|
* length: map(x => x.length)
|
|
16
16
|
* },
|
|
17
17
|
* ["Alice", "Bob", "Charlie"]
|
|
18
|
-
* )]
|
|
19
|
-
*
|
|
18
|
+
* )];
|
|
19
|
+
*
|
|
20
|
+
* console.log(res);
|
|
21
|
+
* // [
|
|
22
|
+
* // { length: 5, upper: 'ALICE', initial: 'A' },
|
|
20
23
|
* // { length: 3, upper: 'BOB', initial: 'B' },
|
|
21
|
-
* // { length: 7, upper: 'CHARLIE', initial: 'C' }
|
|
24
|
+
* // { length: 7, upper: 'CHARLIE', initial: 'C' }
|
|
25
|
+
* // ]
|
|
22
26
|
* ```
|
|
23
27
|
*
|
|
24
28
|
* @param xforms - object of transducers
|
package/multiplex.d.ts
CHANGED
|
@@ -21,26 +21,27 @@ import type { MultiplexTxLike, Transducer } from "./api.js";
|
|
|
21
21
|
* should be used.
|
|
22
22
|
*
|
|
23
23
|
* @example
|
|
24
|
-
* ```ts
|
|
24
|
+
* ```ts tangle:../export/multiplex.ts
|
|
25
25
|
* import { iterator, map, multiplex } from "@thi.ng/transducers";
|
|
26
26
|
*
|
|
27
|
-
* [...iterator(
|
|
27
|
+
* const res = [...iterator(
|
|
28
28
|
* multiplex(
|
|
29
29
|
* map(x => x.charAt(0)),
|
|
30
30
|
* map(x => x.toUpperCase()),
|
|
31
31
|
* map(x => x.length)
|
|
32
32
|
* ),
|
|
33
33
|
* ["Alice", "Bob", "Charlie"]
|
|
34
|
-
* )]
|
|
34
|
+
* )];
|
|
35
35
|
*
|
|
36
|
+
* console.log(res);
|
|
36
37
|
* // [ [ "A", "ALICE", 5 ], [ "B", "BOB", 3 ], [ "C", "CHARLIE", 7 ] ]
|
|
37
38
|
* ```
|
|
38
39
|
*
|
|
39
40
|
* @example
|
|
40
|
-
* ```ts
|
|
41
|
+
* ```ts tangle:../export/multiplex-2.ts
|
|
41
42
|
* import { iterator, map, mapcat, multiplex } from "@thi.ng/transducers";
|
|
42
43
|
*
|
|
43
|
-
* [...iterator(
|
|
44
|
+
* const res = [...iterator(
|
|
44
45
|
* multiplex(
|
|
45
46
|
* // override default unwrap behavior for this transducer
|
|
46
47
|
* // (i.e. here to ensure results are always arrays)
|
|
@@ -49,8 +50,9 @@ import type { MultiplexTxLike, Transducer } from "./api.js";
|
|
|
49
50
|
* map((x) => x),
|
|
50
51
|
* ),
|
|
51
52
|
* [[1, 2], [3]]
|
|
52
|
-
* )]
|
|
53
|
+
* )];
|
|
53
54
|
*
|
|
55
|
+
* console.log(res);
|
|
54
56
|
* // [ [ [ 1, 2 ], [ 1, 2 ] ], [ [ 3 ], [ 3 ] ] ]
|
|
55
57
|
*
|
|
56
58
|
* // to compare: using the default behavior would produce this instead
|
package/norm-count.d.ts
CHANGED
|
@@ -9,18 +9,20 @@ import type { Reducer } from "./api.js";
|
|
|
9
9
|
* normalized histogram.
|
|
10
10
|
*
|
|
11
11
|
* @example
|
|
12
|
-
* ```ts
|
|
12
|
+
* ```ts tangle:../export/norm-count.ts
|
|
13
13
|
* import { filter, normCount, transduce } from "@thi.ng/transducers";
|
|
14
14
|
*
|
|
15
15
|
* const items = [1,2,3,1,1,4,2,5,1,2];
|
|
16
16
|
*
|
|
17
17
|
* // compute percentage of values < 3
|
|
18
|
-
*
|
|
18
|
+
* console.log(
|
|
19
|
+
* transduce(filter(x => x<3), normCount(items.length), items)
|
|
20
|
+
* );
|
|
19
21
|
* // 0.7
|
|
20
22
|
* ```
|
|
21
23
|
*
|
|
22
24
|
* @param norm -
|
|
23
25
|
*/
|
|
24
26
|
export declare function normCount(norm: number): Reducer<any, number>;
|
|
25
|
-
export declare function normCount(norm: number,
|
|
27
|
+
export declare function normCount(norm: number, src: Iterable<any>): number;
|
|
26
28
|
//# sourceMappingURL=norm-count.d.ts.map
|
|
@@ -5,21 +5,25 @@ import type { Reducer } from "./api.js";
|
|
|
5
5
|
* basis instead of requiring it ahead of time as argument.
|
|
6
6
|
*
|
|
7
7
|
* @example
|
|
8
|
-
* ```ts
|
|
8
|
+
* ```ts tangle:../export/norm-frequencies-auto.ts
|
|
9
9
|
* import { normFrequenciesAuto } from "@thi.ng/transducers";
|
|
10
10
|
*
|
|
11
11
|
* const items = [1, 2, 3, 1, 1, 4, 2, 5, 1, 2];
|
|
12
12
|
*
|
|
13
|
-
*
|
|
13
|
+
* console.log(
|
|
14
|
+
* normFrequenciesAuto(items)
|
|
15
|
+
* );
|
|
14
16
|
* // Map(5) { 1 => 0.4, 2 => 0.3, 3 => 0.1, 4 => 0.1, 5 => 0.1 }
|
|
15
17
|
*
|
|
16
18
|
* // frequencies by 1st letter
|
|
17
|
-
*
|
|
19
|
+
* console.log(
|
|
20
|
+
* normFrequenciesAuto(x => x[0], ["alice", "abba", "bob", "charlie"])
|
|
21
|
+
* );
|
|
18
22
|
* // Map(3) { 'a' => 0.5, 'b' => 0.25, 'c' => 0.25 }
|
|
19
23
|
* ```
|
|
20
24
|
*/
|
|
21
25
|
export declare function normFrequenciesAuto<A>(): Reducer<A, Map<A, number>>;
|
|
22
|
-
export declare function normFrequenciesAuto<A>(
|
|
26
|
+
export declare function normFrequenciesAuto<A>(src: Iterable<A>): Map<A, number>;
|
|
23
27
|
export declare function normFrequenciesAuto<A, B>(key: Fn<A, B>): Reducer<A, Map<B, number>>;
|
|
24
|
-
export declare function normFrequenciesAuto<A, B>(key: Fn<A, B>,
|
|
28
|
+
export declare function normFrequenciesAuto<A, B>(key: Fn<A, B>, src: Iterable<A>): Map<B, number>;
|
|
25
29
|
//# sourceMappingURL=norm-frequencies-auto.d.ts.map
|
package/norm-frequencies.d.ts
CHANGED
|
@@ -8,19 +8,27 @@ import type { Reducer } from "./api.js";
|
|
|
8
8
|
* Also see {@link normFrequenciesAuto}.
|
|
9
9
|
*
|
|
10
10
|
* @example
|
|
11
|
-
* ```ts
|
|
11
|
+
* ```ts tangle:../export/norm-frequencies.ts
|
|
12
12
|
* import { normFrequencies } from "@thi.ng/transducers";
|
|
13
13
|
*
|
|
14
14
|
* const items = [1, 2, 3, 1, 1, 4, 2, 5, 1, 2];
|
|
15
15
|
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
16
|
+
* console.log(
|
|
17
|
+
* normFrequencies(10, items)
|
|
18
|
+
* );
|
|
19
|
+
* // Map(5) {
|
|
20
|
+
* // 1 => 0.4,
|
|
21
|
+
* // 2 => 0.3,
|
|
22
|
+
* // 3 => 0.1,
|
|
23
|
+
* // 4 => 0.1,
|
|
24
|
+
* // 5 => 0.1,
|
|
25
|
+
* // }
|
|
18
26
|
* ```
|
|
19
27
|
*
|
|
20
28
|
* @param norm -
|
|
21
29
|
*/
|
|
22
30
|
export declare function normFrequencies<A>(norm: number): Reducer<A, Map<A, number>>;
|
|
23
|
-
export declare function normFrequencies<A>(norm: number,
|
|
31
|
+
export declare function normFrequencies<A>(norm: number, src: Iterable<A>): Map<A, number>;
|
|
24
32
|
export declare function normFrequencies<A, B>(norm: number, key: Fn<A, B>): Reducer<A, Map<B, number>>;
|
|
25
|
-
export declare function normFrequencies<A, B>(norm: number, key: Fn<A, B>,
|
|
33
|
+
export declare function normFrequencies<A, B>(norm: number, key: Fn<A, B>, src: Iterable<A>): Map<B, number>;
|
|
26
34
|
//# sourceMappingURL=norm-frequencies.d.ts.map
|
package/norm-range.d.ts
CHANGED
|
@@ -4,19 +4,27 @@
|
|
|
4
4
|
* is true, the values are emitted in reverse order, i.e. from 1.0 → 0.0.
|
|
5
5
|
*
|
|
6
6
|
* @example
|
|
7
|
-
* ```ts
|
|
7
|
+
* ```ts tangle:../export/norm-range.ts
|
|
8
8
|
* import { normRange } from "@thi.ng/transducers";
|
|
9
9
|
*
|
|
10
|
-
*
|
|
10
|
+
* console.log(
|
|
11
|
+
* [...normRange(4)]
|
|
12
|
+
* );
|
|
11
13
|
* // [0, 0.25, 0.5, 0.75, 1.0]
|
|
12
14
|
*
|
|
13
|
-
*
|
|
15
|
+
* console.log(
|
|
16
|
+
* [...normRange(4, false)]
|
|
17
|
+
* );
|
|
14
18
|
* // [0, 0.25, 0.5, 0.75]
|
|
15
19
|
*
|
|
16
|
-
*
|
|
20
|
+
* console.log(
|
|
21
|
+
* [...normRange(4, true, true)]
|
|
22
|
+
* );
|
|
17
23
|
* // [1, 0.75, 0.5, 0.25, 0]
|
|
18
24
|
*
|
|
19
|
-
*
|
|
25
|
+
* console.log(
|
|
26
|
+
* [...normRange(4, false, true)]
|
|
27
|
+
* );
|
|
20
28
|
* // [1, 0.75, 0.5, 0.25]
|
|
21
29
|
* ```
|
|
22
30
|
*
|