@thi.ng/transducers 9.0.5 → 9.0.7
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 -3
- 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/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Change Log
|
|
2
2
|
|
|
3
|
-
- **Last updated**: 2024-
|
|
3
|
+
- **Last updated**: 2024-06-29T09:28:36Z
|
|
4
4
|
- **Generator**: [thi.ng/monopub](https://thi.ng/monopub)
|
|
5
5
|
|
|
6
6
|
All notable changes to this project will be documented in this file.
|
|
@@ -9,6 +9,14 @@ See [Conventional Commits](https://conventionalcommits.org/) for commit guidelin
|
|
|
9
9
|
**Note:** Unlisted _patch_ versions only involve non-code or otherwise excluded changes
|
|
10
10
|
and/or version bumps of transitive dependencies.
|
|
11
11
|
|
|
12
|
+
### [9.0.6](https://github.com/thi-ng/umbrella/tree/@thi.ng/transducers@9.0.6) (2024-06-21)
|
|
13
|
+
|
|
14
|
+
#### ♻️ Refactoring
|
|
15
|
+
|
|
16
|
+
- rename various rest args to be more semantically meaningful ([8088a56](https://github.com/thi-ng/umbrella/commit/8088a56))
|
|
17
|
+
- enforce uniform naming convention of internal functions ([56992b2](https://github.com/thi-ng/umbrella/commit/56992b2))
|
|
18
|
+
- dedupe min/maxCompare() impls, add tests ([22fc6e3](https://github.com/thi-ng/umbrella/commit/22fc6e3))
|
|
19
|
+
|
|
12
20
|
### [9.0.2](https://github.com/thi-ng/umbrella/tree/@thi.ng/transducers@9.0.2) (2024-04-20)
|
|
13
21
|
|
|
14
22
|
#### ♻️ Refactoring
|
package/README.md
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
[](https://mastodon.thi.ng/@toxi)
|
|
8
8
|
|
|
9
9
|
> [!NOTE]
|
|
10
|
-
> This is one of
|
|
10
|
+
> This is one of 189 standalone projects, maintained as part
|
|
11
11
|
> of the [@thi.ng/umbrella](https://github.com/thi-ng/umbrella/) monorepo
|
|
12
12
|
> and anti-framework.
|
|
13
13
|
>
|
|
@@ -113,7 +113,6 @@ change for custom reducer impls.
|
|
|
113
113
|
|
|
114
114
|
- [@thi.ng/csv](https://github.com/thi-ng/umbrella/tree/develop/packages/csv) - Customizable, transducer-based CSV parser/object mapper and transformer
|
|
115
115
|
- [@thi.ng/grid-iterators](https://github.com/thi-ng/umbrella/tree/develop/packages/grid-iterators) - 2D grid and shape iterators w/ multiple orderings
|
|
116
|
-
- [@thi.ng/fsm](https://github.com/thi-ng/umbrella/tree/develop/packages/fsm) - Composable primitives for building declarative, transducer based Finite-State Machines & matchers for arbitrary data streams
|
|
117
116
|
- [@thi.ng/rstream](https://github.com/thi-ng/umbrella/tree/develop/packages/rstream) - Reactive streams & subscription primitives for constructing dataflow graphs / pipelines
|
|
118
117
|
- [@thi.ng/rstream-graph](https://github.com/thi-ng/umbrella/tree/develop/packages/rstream-graph) - Declarative dataflow graph construction for [@thi.ng/rstream](https://github.com/thi-ng/umbrella/tree/develop/packages/rstream)
|
|
119
118
|
- [@thi.ng/rstream-log](https://github.com/thi-ng/umbrella/tree/develop/packages/rstream-log) - Structured, multilevel & hierarchical loggers based on [@thi.ng/rstream](https://github.com/thi-ng/umbrella/tree/develop/packages/rstream)
|
|
@@ -151,7 +150,7 @@ For Node.js REPL:
|
|
|
151
150
|
const tx = await import("@thi.ng/transducers");
|
|
152
151
|
```
|
|
153
152
|
|
|
154
|
-
Package sizes (brotli'd, pre-treeshake): ESM: 8.
|
|
153
|
+
Package sizes (brotli'd, pre-treeshake): ESM: 8.94 KB
|
|
155
154
|
|
|
156
155
|
## Dependencies
|
|
157
156
|
|
|
@@ -186,6 +185,8 @@ directory are using this package:
|
|
|
186
185
|
| <img src="https://raw.githubusercontent.com/thi-ng/umbrella/develop/assets/examples/fft-synth.png" width="240"/> | Interactive inverse FFT toy synth | [Demo](https://demo.thi.ng/umbrella/fft-synth/) | [Source](https://github.com/thi-ng/umbrella/tree/develop/examples/fft-synth) |
|
|
187
186
|
| <img src="https://raw.githubusercontent.com/thi-ng/umbrella/develop/assets/examples/fiber-basics.png" width="240"/> | Fiber-based cooperative multitasking basics | [Demo](https://demo.thi.ng/umbrella/fiber-basics/) | [Source](https://github.com/thi-ng/umbrella/tree/develop/examples/fiber-basics) |
|
|
188
187
|
| <img src="https://raw.githubusercontent.com/thi-ng/umbrella/develop/assets/examples/geom-complex-poly.png" width="240"/> | Shape conversions & operations using polygons with holes | [Demo](https://demo.thi.ng/umbrella/geom-complex-poly/) | [Source](https://github.com/thi-ng/umbrella/tree/develop/examples/geom-complex-poly) |
|
|
188
|
+
| <img src="https://raw.githubusercontent.com/thi-ng/umbrella/develop/assets/examples/geom-csv-piechart.png" width="240"/> | Piechart visualization of CSV data | [Demo](https://demo.thi.ng/umbrella/geom-csv-piechart/) | [Source](https://github.com/thi-ng/umbrella/tree/develop/examples/geom-csv-piechart) |
|
|
189
|
+
| <img src="https://raw.githubusercontent.com/thi-ng/umbrella/develop/assets/examples/geom-hexgrid.png" width="240"/> | Hex grid generation & tessellations | [Demo](https://demo.thi.ng/umbrella/geom-hexgrid/) | [Source](https://github.com/thi-ng/umbrella/tree/develop/examples/geom-hexgrid) |
|
|
189
190
|
| <img src="https://raw.githubusercontent.com/thi-ng/umbrella/develop/assets/examples/grid-iterators.png" width="240"/> | Visualization of different grid iterator strategies | [Demo](https://demo.thi.ng/umbrella/grid-iterators/) | [Source](https://github.com/thi-ng/umbrella/tree/develop/examples/grid-iterators) |
|
|
190
191
|
| <img src="https://raw.githubusercontent.com/thi-ng/umbrella/develop/assets/examples/hdom-benchmark2.png" width="240"/> | hdom update performance benchmark w/ config options | [Demo](https://demo.thi.ng/umbrella/hdom-benchmark2/) | [Source](https://github.com/thi-ng/umbrella/tree/develop/examples/hdom-benchmark2) |
|
|
191
192
|
| <img src="https://raw.githubusercontent.com/thi-ng/umbrella/develop/assets/examples/hdom-canvas-clock.png" width="240"/> | Realtime analog clock demo | [Demo](https://demo.thi.ng/umbrella/hdom-canvas-clock/) | [Source](https://github.com/thi-ng/umbrella/tree/develop/examples/hdom-canvas-clock) |
|
package/add.d.ts
CHANGED
|
@@ -3,6 +3,6 @@ import type { Reducer } from "./api.js";
|
|
|
3
3
|
* Reducer to compute sum of values with given `init` value. Default: 0
|
|
4
4
|
*/
|
|
5
5
|
export declare function add(init?: number): Reducer<number, number>;
|
|
6
|
-
export declare function add(
|
|
7
|
-
export declare function add(init: number,
|
|
6
|
+
export declare function add(src: Iterable<number>): number;
|
|
7
|
+
export declare function add(init: number, src: Iterable<number>): number;
|
|
8
8
|
//# sourceMappingURL=add.d.ts.map
|
package/add.js
CHANGED
package/api.d.ts
CHANGED
|
@@ -30,6 +30,7 @@ export type ReductionFn<A, B> = (acc: B, x: A) => B | Reduced<B>;
|
|
|
30
30
|
* existing (partially) reduced result.
|
|
31
31
|
*/
|
|
32
32
|
export type Reducer<A, B> = [Fn0<B>, Fn<B, B>, ReductionFn<A, B>];
|
|
33
|
+
export type MaybeReduced<T> = Reduced<T> | T;
|
|
33
34
|
/**
|
|
34
35
|
* Interface for types able to provide some internal functionality (or
|
|
35
36
|
* derive some related transformation) as {@link Transducer}.
|
|
@@ -37,23 +38,25 @@ export type Reducer<A, B> = [Fn0<B>, Fn<B, B>, ReductionFn<A, B>];
|
|
|
37
38
|
* functions in this package where a `Transducer` arg is expected.
|
|
38
39
|
*
|
|
39
40
|
* @example
|
|
40
|
-
* ```ts
|
|
41
|
+
* ```ts tangle:../export/ixform.ts
|
|
41
42
|
* import {
|
|
42
|
-
* comp, drop, map, push, range, transduce
|
|
43
|
+
* comp, drop, map, push, range, takeNth, transduce,
|
|
43
44
|
* type IXform
|
|
44
45
|
* } from "@thi.ng/transducers";
|
|
45
46
|
*
|
|
46
47
|
* class Mul implements IXform<number, number> {
|
|
47
48
|
* constructor(public factor = 10) {}
|
|
48
49
|
*
|
|
49
|
-
* xform() { return map((x) => this.factor * x); }
|
|
50
|
+
* xform() { return map((x: number) => this.factor * x); }
|
|
50
51
|
* }
|
|
51
52
|
*
|
|
52
|
-
*
|
|
53
|
+
* console.log(
|
|
54
|
+
* transduce(new Mul(11), push(), range(4))
|
|
55
|
+
* );
|
|
53
56
|
* // [0, 11, 22, 33, 44]
|
|
54
57
|
*
|
|
55
58
|
* // also usable w/ comp()
|
|
56
|
-
* transduce(
|
|
59
|
+
* const res = transduce(
|
|
57
60
|
* comp(
|
|
58
61
|
* drop(1),
|
|
59
62
|
* new Mul(11),
|
|
@@ -61,7 +64,9 @@ export type Reducer<A, B> = [Fn0<B>, Fn<B, B>, ReductionFn<A, B>];
|
|
|
61
64
|
* ),
|
|
62
65
|
* push(),
|
|
63
66
|
* range(4)
|
|
64
|
-
* )
|
|
67
|
+
* );
|
|
68
|
+
*
|
|
69
|
+
* console.log(res);
|
|
65
70
|
* // [11, 33]
|
|
66
71
|
* ```
|
|
67
72
|
*/
|
package/assoc-map.d.ts
CHANGED
|
@@ -2,8 +2,8 @@ import type { Pair } from "@thi.ng/api";
|
|
|
2
2
|
import type { Reducer } from "./api.js";
|
|
3
3
|
/**
|
|
4
4
|
* Reducer accepting key-value pairs / tuples and transforming / adding
|
|
5
|
-
* them to an ES6 Map.
|
|
5
|
+
* them to an ES6 Map. Also see {@link assocObj}.
|
|
6
6
|
*/
|
|
7
7
|
export declare function assocMap<A, B>(): Reducer<Pair<A, B>, Map<A, B>>;
|
|
8
|
-
export declare function assocMap<A, B>(
|
|
8
|
+
export declare function assocMap<A, B>(src: Iterable<Pair<A, B>>): Map<A, B>;
|
|
9
9
|
//# sourceMappingURL=assoc-map.d.ts.map
|
package/assoc-map.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { reduce, reducer } from "./reduce.js";
|
|
2
|
-
function assocMap(
|
|
3
|
-
return
|
|
2
|
+
function assocMap(src) {
|
|
3
|
+
return src ? reduce(assocMap(), src) : reducer(
|
|
4
4
|
() => /* @__PURE__ */ new Map(),
|
|
5
5
|
(acc, [k, v]) => acc.set(k, v)
|
|
6
6
|
);
|
package/assoc-obj.d.ts
CHANGED
|
@@ -2,8 +2,8 @@ import type { IObjectOf, Pair } from "@thi.ng/api";
|
|
|
2
2
|
import type { Reducer } from "./api.js";
|
|
3
3
|
/**
|
|
4
4
|
* Reducer accepting key-value pairs / tuples and updating / adding them
|
|
5
|
-
* to an object.
|
|
5
|
+
* to an object. Also see {@link assocMap}.
|
|
6
6
|
*/
|
|
7
7
|
export declare function assocObj<T>(): Reducer<Pair<PropertyKey, T>, IObjectOf<T>>;
|
|
8
|
-
export declare function assocObj<T>(
|
|
8
|
+
export declare function assocObj<T>(src: Iterable<Pair<PropertyKey, T>>): IObjectOf<T>;
|
|
9
9
|
//# sourceMappingURL=assoc-obj.d.ts.map
|
package/assoc-obj.js
CHANGED
package/auto-obj.d.ts
CHANGED
|
@@ -5,15 +5,17 @@ import type { Reducer } from "./api.js";
|
|
|
5
5
|
* in an object. Keys consist of given `prefix` and monotonically increasing ID.
|
|
6
6
|
*
|
|
7
7
|
* @example
|
|
8
|
-
* ```ts
|
|
8
|
+
* ```ts tangle:../export/auto-obj.ts
|
|
9
9
|
* import { autoObj } from "@thi.ng/transducers";
|
|
10
10
|
*
|
|
11
|
-
*
|
|
11
|
+
* console.log(
|
|
12
|
+
* autoObj("id", ["foo", "bar", "baz"])
|
|
13
|
+
* );
|
|
12
14
|
* // { id0: "foo", id1: "bar", id2: "baz" }
|
|
13
15
|
* ```
|
|
14
16
|
*
|
|
15
17
|
* @param prefix - shared prefix
|
|
16
18
|
*/
|
|
17
19
|
export declare function autoObj<T>(prefix: string): Reducer<T, IObjectOf<T>>;
|
|
18
|
-
export declare function autoObj<T>(prefix: string,
|
|
20
|
+
export declare function autoObj<T>(prefix: string, src: Iterable<T>): IObjectOf<T>;
|
|
19
21
|
//# sourceMappingURL=auto-obj.d.ts.map
|
package/auto-obj.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { reduce, reducer } from "./reduce.js";
|
|
2
|
-
function autoObj(prefix,
|
|
2
|
+
function autoObj(prefix, src) {
|
|
3
3
|
let id = 0;
|
|
4
|
-
return
|
|
4
|
+
return src ? reduce(autoObj(prefix), src) : reducer(
|
|
5
5
|
() => ({}),
|
|
6
6
|
(acc, v) => (acc[prefix + id++] = v, acc)
|
|
7
7
|
);
|
package/benchmark.d.ts
CHANGED
|
@@ -5,13 +5,19 @@ import type { Transducer } from "./api.js";
|
|
|
5
5
|
* e.g. for use in async usage contexts.
|
|
6
6
|
*
|
|
7
7
|
* @example
|
|
8
|
-
* ```ts
|
|
8
|
+
* ```ts tangle:../export/benchmark.ts
|
|
9
9
|
* import { fromInterval, trace } from "@thi.ng/rstream";
|
|
10
|
+
* import { benchmark, comp, movingAverage } from "@thi.ng/transducers";
|
|
10
11
|
*
|
|
11
|
-
* fromInterval(
|
|
12
|
+
* fromInterval(16).subscribe(
|
|
12
13
|
* trace(),
|
|
13
14
|
* { xform: comp(benchmark(), movingAverage(60)) }
|
|
14
|
-
* )
|
|
15
|
+
* );
|
|
16
|
+
* // 16.766666666666666
|
|
17
|
+
* // 17.05
|
|
18
|
+
* // 17.033333333333335
|
|
19
|
+
* // 17.033333333333335
|
|
20
|
+
* // ...
|
|
15
21
|
* ```
|
|
16
22
|
*/
|
|
17
23
|
export declare function benchmark(): Transducer<any, number>;
|
package/cat.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { 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 to concatenate iterable values. Iterates over each input and emits
|
|
5
5
|
* individual values down stream, therefore removing one level of nesting from
|
|
@@ -15,29 +15,35 @@ import type { Transducer } from "./api.js";
|
|
|
15
15
|
* Also see {@link concat}, {@link mapcat}.
|
|
16
16
|
*
|
|
17
17
|
* @example
|
|
18
|
-
* ```ts
|
|
18
|
+
* ```ts tangle:../export/cat.ts
|
|
19
19
|
* import {
|
|
20
20
|
* cat, comp, iterator, map, mapcat, mapIndexed, reduced
|
|
21
21
|
* } from "@thi.ng/transducers";
|
|
22
22
|
*
|
|
23
|
-
*
|
|
23
|
+
* console.log(
|
|
24
|
+
* [...iterator(comp(map((x) => [x, x]), cat()), [1, 2, 3, 4])]
|
|
25
|
+
* );
|
|
24
26
|
* // [ 1, 1, 2, 2, 3, 3, 4, 4 ]
|
|
25
27
|
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
*
|
|
28
|
+
* console.log(
|
|
29
|
+
* [...iterator(
|
|
30
|
+
* comp(
|
|
31
|
+
* mapIndexed((i, x) => [[i], [x, x]]),
|
|
32
|
+
* cat<(number | string)[]>(),
|
|
33
|
+
* cat()
|
|
34
|
+
* ),
|
|
35
|
+
* "abc"
|
|
36
|
+
* )]
|
|
37
|
+
* );
|
|
34
38
|
* // [ 0, 'a', 'a', 1, 'b', 'b', 2, 'c', 'c' ]
|
|
35
39
|
*
|
|
36
|
-
*
|
|
40
|
+
* console.log(
|
|
41
|
+
* [...mapcat((x)=>(x > 1 ? reduced([x, x]) : [x, x]), [1, 2, 3, 4])]
|
|
42
|
+
* );
|
|
37
43
|
* // [ 1, 1, 2, 2 ]
|
|
38
44
|
* ```
|
|
39
45
|
*
|
|
40
46
|
* @param rfn -
|
|
41
47
|
*/
|
|
42
|
-
export declare const cat: <T>() => Transducer<Nullable<Iterable<T
|
|
48
|
+
export declare const cat: <T>() => Transducer<MaybeReduced<Nullable<Iterable<T>>>, T>;
|
|
43
49
|
//# sourceMappingURL=cat.d.ts.map
|
package/cat.js
CHANGED
package/choices.d.ts
CHANGED
|
@@ -9,11 +9,22 @@ import type { IRandom } from "@thi.ng/random";
|
|
|
9
9
|
* [`weightedRandom()`](https://docs.thi.ng/umbrella/random/functions/weightedRandom.html).
|
|
10
10
|
*
|
|
11
11
|
* @example
|
|
12
|
-
* ```ts
|
|
12
|
+
* ```ts tangle:../export/choices.ts
|
|
13
13
|
* import { choices, frequencies, take, transduce } from "@thi.ng/transducers";
|
|
14
14
|
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
15
|
+
* const res = transduce(
|
|
16
|
+
* take(1000),
|
|
17
|
+
* frequencies(),
|
|
18
|
+
* choices("abcd", [1, 0.5, 0.25, 0.125])
|
|
19
|
+
* );
|
|
20
|
+
*
|
|
21
|
+
* console.log(res);
|
|
22
|
+
* // Map(4) {
|
|
23
|
+
* // "a": 544,
|
|
24
|
+
* // "b": 263,
|
|
25
|
+
* // "c": 131,
|
|
26
|
+
* // "d": 62,
|
|
27
|
+
* // }
|
|
17
28
|
* ```
|
|
18
29
|
*
|
|
19
30
|
* @param choices -
|
package/concat.d.ts
CHANGED
|
@@ -5,17 +5,21 @@ import type { Nullable } from "@thi.ng/api";
|
|
|
5
5
|
* such values produced or contained in an input will remain.
|
|
6
6
|
*
|
|
7
7
|
* @example
|
|
8
|
-
* ```ts
|
|
8
|
+
* ```ts tangle:../export/concat.ts
|
|
9
9
|
* import { concat } from "@thi.ng/transducers";
|
|
10
10
|
*
|
|
11
|
-
*
|
|
11
|
+
* console.log(
|
|
12
|
+
* [...concat([1, 2, 3], null, [4, 5])]
|
|
13
|
+
* );
|
|
12
14
|
* // [ 1, 2, 3, 4, 5 ]
|
|
13
15
|
*
|
|
14
|
-
*
|
|
16
|
+
* console.log(
|
|
17
|
+
* [...concat([1, 2, 3, undefined], null, [4, 5])]
|
|
18
|
+
* );
|
|
15
19
|
* // [ 1, 2, 3, undefined, 4, 5 ]
|
|
16
20
|
* ```
|
|
17
21
|
*
|
|
18
|
-
* @param
|
|
22
|
+
* @param sources -
|
|
19
23
|
*/
|
|
20
|
-
export declare function concat<T>(...
|
|
24
|
+
export declare function concat<T>(...sources: Nullable<Iterable<T>>[]): IterableIterator<T>;
|
|
21
25
|
//# sourceMappingURL=concat.d.ts.map
|
package/concat.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ensureIterable } from "@thi.ng/arrays/ensure-iterable";
|
|
2
|
-
function* concat(...
|
|
3
|
-
for (let
|
|
4
|
-
|
|
2
|
+
function* concat(...sources) {
|
|
3
|
+
for (let src of sources) {
|
|
4
|
+
src != null && (yield* ensureIterable(src));
|
|
5
5
|
}
|
|
6
6
|
}
|
|
7
7
|
export {
|
package/conj.d.ts
CHANGED
|
@@ -3,5 +3,5 @@ import type { Reducer } from "./api.js";
|
|
|
3
3
|
* Reducer. Like {@link push}, but for ES6 Sets.
|
|
4
4
|
*/
|
|
5
5
|
export declare function conj<T>(): Reducer<T, Set<T>>;
|
|
6
|
-
export declare function conj<T>(
|
|
6
|
+
export declare function conj<T>(src: Iterable<T>): Set<T>;
|
|
7
7
|
//# sourceMappingURL=conj.d.ts.map
|
package/conj.js
CHANGED
package/consume.d.ts
CHANGED
|
@@ -7,10 +7,14 @@
|
|
|
7
7
|
* should be applied.
|
|
8
8
|
*
|
|
9
9
|
* @example
|
|
10
|
-
* ```ts
|
|
10
|
+
* ```ts tangle:../export/consume.ts
|
|
11
11
|
* import { consume, repeatedly2d } from "@thi.ng/transducers";
|
|
12
12
|
*
|
|
13
|
-
*
|
|
13
|
+
* // iterators are lazy, no logging will actually be performed yet
|
|
14
|
+
* const iter = repeatedly2d((x, y) => console.log("output:", [x, y]), 2, 3);
|
|
15
|
+
*
|
|
16
|
+
* // force evaluation, discard any results
|
|
17
|
+
* consume(iter);
|
|
14
18
|
* // output: [ 0, 0 ]
|
|
15
19
|
* // output: [ 1, 0 ]
|
|
16
20
|
* // output: [ 0, 1 ]
|
package/converge.d.ts
CHANGED
|
@@ -15,16 +15,18 @@ import type { Transducer } from "./api.js";
|
|
|
15
15
|
* See also: {@link takeWhile}
|
|
16
16
|
*
|
|
17
17
|
* @example
|
|
18
|
-
* ```ts
|
|
18
|
+
* ```ts tangle:../export/converge.ts
|
|
19
19
|
* import { converge, iterate } from "@thi.ng/transducers";
|
|
20
20
|
*
|
|
21
21
|
* // process as long as difference to prev value is >= 0.01
|
|
22
|
-
* [...converge(
|
|
22
|
+
* const res = [...converge(
|
|
23
23
|
* // predicate
|
|
24
24
|
* (a, b) => Math.abs(a - b) < 0.01,
|
|
25
25
|
* // input sequence
|
|
26
26
|
* iterate((x, i) => x + Math.pow(2, -i), 0)
|
|
27
|
-
* )]
|
|
27
|
+
* )];
|
|
28
|
+
*
|
|
29
|
+
* console.log(res);
|
|
28
30
|
* // [ 0, 0.5, 0.75, 0.875, 0.9375, 0.96875, 0.984375, 0.9921875 ]
|
|
29
31
|
* ```
|
|
30
32
|
*
|
package/convolve.js
CHANGED
|
@@ -15,20 +15,20 @@ const buildKernel2d = (weights, w, h = w) => {
|
|
|
15
15
|
const h2 = h >> 1;
|
|
16
16
|
return [...zip(weights, range2d(-w2, w2 + 1, -h2, h2 + 1))];
|
|
17
17
|
};
|
|
18
|
-
const
|
|
18
|
+
const __kernelLookup1d = (src, x, width, wrap, border) => wrap ? ({ 0: w, 1: ox }) => {
|
|
19
19
|
const xx = x < -ox ? width + ox : x >= width - ox ? ox - 1 : x + ox;
|
|
20
20
|
return w * src[xx];
|
|
21
21
|
} : ({ 0: w, 1: ox }) => {
|
|
22
22
|
return x < -ox || x >= width - ox ? border : w * src[x + ox];
|
|
23
23
|
};
|
|
24
|
-
const
|
|
24
|
+
const __kernelLookup2d = (src, x, y, width, height, wrap, border) => wrap ? ({ 0: w, 1: { 0: ox, 1: oy } }) => {
|
|
25
25
|
const xx = x < -ox ? width + ox : x >= width - ox ? ox - 1 : x + ox;
|
|
26
26
|
const yy = y < -oy ? height + oy : y >= height - oy ? oy - 1 : y + oy;
|
|
27
27
|
return w * src[yy * width + xx];
|
|
28
28
|
} : ({ 0: w, 1: { 0: ox, 1: oy } }) => {
|
|
29
29
|
return x < -ox || y < -oy || x >= width - ox || y >= height - oy ? border : w * src[(y + oy) * width + x + ox];
|
|
30
30
|
};
|
|
31
|
-
const
|
|
31
|
+
const __kernelError = () => illegalArgs(`no kernel or kernel config`);
|
|
32
32
|
function convolve1d(opts, indices) {
|
|
33
33
|
if (indices) {
|
|
34
34
|
return iterator1(convolve1d(opts), indices);
|
|
@@ -39,12 +39,12 @@ function convolve1d(opts, indices) {
|
|
|
39
39
|
const rfn = opts.reduce || add;
|
|
40
40
|
let kernel = opts.kernel;
|
|
41
41
|
if (!kernel) {
|
|
42
|
-
!(opts.weights && opts.kwidth) &&
|
|
42
|
+
!(opts.weights && opts.kwidth) && __kernelError();
|
|
43
43
|
kernel = buildKernel1d(opts.weights, opts.kwidth);
|
|
44
44
|
}
|
|
45
45
|
return map(
|
|
46
46
|
(p) => transduce(
|
|
47
|
-
map(
|
|
47
|
+
map(__kernelLookup1d(src, p, width, wrap, border)),
|
|
48
48
|
rfn(),
|
|
49
49
|
kernel
|
|
50
50
|
)
|
|
@@ -60,12 +60,12 @@ function convolve2d(opts, indices) {
|
|
|
60
60
|
const rfn = opts.reduce || add;
|
|
61
61
|
let kernel = opts.kernel;
|
|
62
62
|
if (!kernel) {
|
|
63
|
-
!(opts.weights && opts.kwidth && opts.kheight) &&
|
|
63
|
+
!(opts.weights && opts.kwidth && opts.kheight) && __kernelError();
|
|
64
64
|
kernel = buildKernel2d(opts.weights, opts.kwidth, opts.kheight);
|
|
65
65
|
}
|
|
66
66
|
return map(
|
|
67
67
|
(p) => transduce(
|
|
68
|
-
map(
|
|
68
|
+
map(__kernelLookup2d(src, p[0], p[1], width, height, wrap, border)),
|
|
69
69
|
rfn(),
|
|
70
70
|
kernel
|
|
71
71
|
)
|
package/count.d.ts
CHANGED
|
@@ -7,7 +7,7 @@ import type { Reducer } from "./api.js";
|
|
|
7
7
|
* @param step -
|
|
8
8
|
*/
|
|
9
9
|
export declare function count(offset?: number, step?: number): Reducer<any, number>;
|
|
10
|
-
export declare function count(
|
|
11
|
-
export declare function count(offset: number,
|
|
12
|
-
export declare function count(offset: number, step: number,
|
|
10
|
+
export declare function count(src: Iterable<any>): number;
|
|
11
|
+
export declare function count(offset: number, src: Iterable<any>): number;
|
|
12
|
+
export declare function count(offset: number, step: number, src: Iterable<any>): number;
|
|
13
13
|
//# sourceMappingURL=count.d.ts.map
|
package/curve.d.ts
CHANGED
|
@@ -14,12 +14,14 @@
|
|
|
14
14
|
* [`curve()`](https://docs.thi.ng/umbrella/dsp/functions/curve.html).
|
|
15
15
|
*
|
|
16
16
|
* @example
|
|
17
|
-
* ```ts
|
|
17
|
+
* ```ts tangle:../export/curve.ts
|
|
18
18
|
* import { curve } from "@thi.ng/transducers";
|
|
19
19
|
*
|
|
20
|
-
*
|
|
20
|
+
* console.log(
|
|
21
|
+
* [...curve(50, 100, 10)]
|
|
22
|
+
* );
|
|
21
23
|
* // [
|
|
22
|
-
* // 50,
|
|
24
|
+
* // 50.000,
|
|
23
25
|
* // 73.193,
|
|
24
26
|
* // 85.649,
|
|
25
27
|
* // 92.339,
|
|
@@ -29,7 +31,7 @@
|
|
|
29
31
|
* // 99.454,
|
|
30
32
|
* // 99.753,
|
|
31
33
|
* // 99.913,
|
|
32
|
-
* // 100
|
|
34
|
+
* // 100.000
|
|
33
35
|
* // ]
|
|
34
36
|
* ```
|
|
35
37
|
*
|
package/cycle.d.ts
CHANGED
|
@@ -7,15 +7,19 @@
|
|
|
7
7
|
* Also see {@link repeat}, {@link repeatedly} for related functions.
|
|
8
8
|
*
|
|
9
9
|
* @example
|
|
10
|
-
* ```ts
|
|
10
|
+
* ```ts tangle:../export/cycle.ts
|
|
11
11
|
* import { cycle, range, take } from "@thi.ng/transducers";
|
|
12
12
|
*
|
|
13
13
|
* // take 5 from infinite sequence
|
|
14
|
-
*
|
|
14
|
+
* console.log(
|
|
15
|
+
* [...take(5, cycle([1, 2, 3]))]
|
|
16
|
+
* );
|
|
15
17
|
* // [1, 2, 3, 1, 2]
|
|
16
18
|
*
|
|
17
19
|
* // only produce 2 cycles
|
|
18
|
-
*
|
|
20
|
+
* console.log(
|
|
21
|
+
* [...cycle(range(3), 2)]
|
|
22
|
+
* );
|
|
19
23
|
* // [ 0, 1, 2, 0, 1, 2 ]
|
|
20
24
|
* ```
|
|
21
25
|
*
|
package/dedupe.d.ts
CHANGED
|
@@ -8,10 +8,12 @@ import type { Transducer } from "./api.js";
|
|
|
8
8
|
* See {@link distinct} to remove **any** duplicates.
|
|
9
9
|
*
|
|
10
10
|
* @example
|
|
11
|
-
* ```ts
|
|
11
|
+
* ```ts tangle:../export/dedupe.ts
|
|
12
12
|
* import { dedupe } from "@thi.ng/transducers";
|
|
13
13
|
*
|
|
14
|
-
*
|
|
14
|
+
* console.log(
|
|
15
|
+
* [...dedupe([1, 1, 2, 3, 3, 3, 1])]
|
|
16
|
+
* );
|
|
15
17
|
* // [ 1, 2, 3, 1 ]
|
|
16
18
|
* ```
|
|
17
19
|
*
|
package/deep-transform.d.ts
CHANGED
|
@@ -18,11 +18,11 @@ import type { TransformSpec } from "./api.js";
|
|
|
18
18
|
* given directly without having to wrap it into the usual array structure.
|
|
19
19
|
*
|
|
20
20
|
* @example
|
|
21
|
-
* ```ts
|
|
22
|
-
* import { deepTransform } from "@thi.ng/transducers";
|
|
21
|
+
* ```ts tangle:../export/deep-transform.ts
|
|
22
|
+
* import { deepTransform, type TransformSpec } from "@thi.ng/transducers";
|
|
23
23
|
*
|
|
24
24
|
* // source object to be transformed
|
|
25
|
-
* src = {
|
|
25
|
+
* const src = {
|
|
26
26
|
* meta: {
|
|
27
27
|
* author: { name: "Alice", email: "a@b.com" },
|
|
28
28
|
* date: 1041510896000
|
|
@@ -33,7 +33,7 @@ import type { TransformSpec } from "./api.js";
|
|
|
33
33
|
* };
|
|
34
34
|
*
|
|
35
35
|
* // deep transformation spec
|
|
36
|
-
* spec = [
|
|
36
|
+
* const spec: TransformSpec = [
|
|
37
37
|
* // root transform (called last)
|
|
38
38
|
* ({ type, meta, title, body }) => ["div", { class: type }, title, meta, body],
|
|
39
39
|
* // object of transform sub-specs
|
|
@@ -50,14 +50,15 @@ import type { TransformSpec } from "./api.js";
|
|
|
50
50
|
* ];
|
|
51
51
|
*
|
|
52
52
|
* // build transformer & apply to src
|
|
53
|
-
*
|
|
54
|
-
*
|
|
53
|
+
* console.log(
|
|
54
|
+
* deepTransform(spec)(src)
|
|
55
|
+
* );
|
|
55
56
|
* // [ "div",
|
|
56
|
-
* // { class: "
|
|
57
|
+
* // { class: "post" },
|
|
57
58
|
* // [ "h1", "Hello world" ],
|
|
58
59
|
* // [ "div.meta",
|
|
59
60
|
* // [ "a", { href: "mailto:a@.b.com" }, "Alice" ],
|
|
60
|
-
* // "
|
|
61
|
+
* // "(1/2/2003, 12:34:56 PM)" ],
|
|
61
62
|
* // "Ratione necessitatibus doloremque itaque." ]
|
|
62
63
|
* ```
|
|
63
64
|
*
|
package/distinct.d.ts
CHANGED
|
@@ -17,10 +17,12 @@ export interface DistinctOpts<T> {
|
|
|
17
17
|
* {@link DistinctOpts}.
|
|
18
18
|
*
|
|
19
19
|
* @example
|
|
20
|
-
* ```ts
|
|
20
|
+
* ```ts tangle:../export/distinct.ts
|
|
21
21
|
* import { distinct } from "@thi.ng/transducers";
|
|
22
22
|
*
|
|
23
|
-
*
|
|
23
|
+
* console.log(
|
|
24
|
+
* [...distinct({ key: (x) => x.id }, [{id: 1, x: 2}, {id: 1, x: 3}])]
|
|
25
|
+
* );
|
|
24
26
|
* // [ { id: 1, x: 2 } ]
|
|
25
27
|
* ```
|
|
26
28
|
*
|
package/div.d.ts
CHANGED
|
@@ -4,5 +4,5 @@ import type { Reducer } from "./api.js";
|
|
|
4
4
|
* value.
|
|
5
5
|
*/
|
|
6
6
|
export declare function div(init: number): Reducer<number, number>;
|
|
7
|
-
export declare function div(init: number,
|
|
7
|
+
export declare function div(init: number, src: Iterable<number>): number;
|
|
8
8
|
//# sourceMappingURL=div.d.ts.map
|
package/div.js
CHANGED