@thi.ng/transducers 9.0.4 → 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.
Files changed (157) hide show
  1. package/CHANGELOG.md +9 -1
  2. package/README.md +5 -2
  3. package/add.d.ts +2 -2
  4. package/add.js +2 -2
  5. package/api.d.ts +11 -6
  6. package/assoc-map.d.ts +2 -2
  7. package/assoc-map.js +2 -2
  8. package/assoc-obj.d.ts +2 -2
  9. package/assoc-obj.js +2 -2
  10. package/auto-obj.d.ts +5 -3
  11. package/auto-obj.js +2 -2
  12. package/benchmark.d.ts +9 -3
  13. package/cat.d.ts +19 -13
  14. package/cat.js +1 -1
  15. package/choices.d.ts +14 -3
  16. package/concat.d.ts +9 -5
  17. package/concat.js +3 -3
  18. package/conj.d.ts +1 -1
  19. package/conj.js +2 -2
  20. package/consume.d.ts +6 -2
  21. package/consume.js +1 -2
  22. package/converge.d.ts +5 -3
  23. package/convolve.js +7 -7
  24. package/count.d.ts +3 -3
  25. package/curve.d.ts +6 -4
  26. package/cycle.d.ts +7 -3
  27. package/cycle.js +1 -2
  28. package/dedupe.d.ts +4 -2
  29. package/deep-transform.d.ts +10 -9
  30. package/distinct.d.ts +4 -2
  31. package/div.d.ts +1 -1
  32. package/div.js +2 -2
  33. package/dup.d.ts +10 -5
  34. package/every.d.ts +6 -4
  35. package/every.js +1 -3
  36. package/extend-sides.d.ts +12 -4
  37. package/fill.d.ts +4 -4
  38. package/fill.js +1 -3
  39. package/filter-fuzzy.d.ts +4 -2
  40. package/flatten-with.d.ts +6 -3
  41. package/flatten.d.ts +7 -3
  42. package/flatten1.d.ts +11 -5
  43. package/frequencies.d.ts +2 -2
  44. package/group-binary.d.ts +37 -27
  45. package/group-binary.js +3 -3
  46. package/group-by-map.d.ts +2 -2
  47. package/group-by-map.js +1 -2
  48. package/group-by-obj.d.ts +54 -2
  49. package/group-by-obj.js +1 -2
  50. package/internal/mathop.d.ts +11 -1
  51. package/internal/mathop.js +12 -5
  52. package/interpolate.d.ts +4 -3
  53. package/iterate.d.ts +7 -3
  54. package/iterator.d.ts +4 -4
  55. package/iterator.js +4 -4
  56. package/juxtr.d.ts +8 -2
  57. package/key-permutations.d.ts +4 -2
  58. package/last.d.ts +1 -1
  59. package/last.js +2 -2
  60. package/length.d.ts +4 -2
  61. package/line.d.ts +4 -2
  62. package/lookup.d.ts +8 -4
  63. package/map-indexed.d.ts +6 -8
  64. package/map-keys.d.ts +5 -3
  65. package/map-nth.d.ts +10 -6
  66. package/map-vals.d.ts +4 -2
  67. package/map.d.ts +4 -2
  68. package/mapcat.d.ts +10 -6
  69. package/match-first.d.ts +16 -17
  70. package/match-last.d.ts +12 -8
  71. package/max-compare.d.ts +3 -3
  72. package/max-compare.js +2 -9
  73. package/max-mag.d.ts +1 -1
  74. package/max-mag.js +2 -2
  75. package/max.d.ts +1 -1
  76. package/max.js +2 -2
  77. package/mean.d.ts +1 -1
  78. package/mean.js +2 -2
  79. package/min-compare.d.ts +3 -3
  80. package/min-compare.js +2 -9
  81. package/min-mag.d.ts +1 -1
  82. package/min-mag.js +2 -2
  83. package/min.d.ts +1 -1
  84. package/min.js +2 -2
  85. package/moving-median.js +1 -2
  86. package/mul.d.ts +2 -2
  87. package/mul.js +2 -2
  88. package/multiplex-obj.d.ts +10 -6
  89. package/multiplex.d.ts +8 -6
  90. package/norm-count.d.ts +5 -3
  91. package/norm-count.js +1 -2
  92. package/norm-frequencies-auto.d.ts +9 -5
  93. package/norm-frequencies-auto.js +1 -2
  94. package/norm-frequencies.d.ts +13 -5
  95. package/norm-range.d.ts +13 -5
  96. package/package.json +15 -15
  97. package/pad-last.d.ts +24 -15
  98. package/pad-sides.d.ts +27 -5
  99. package/page.d.ts +13 -5
  100. package/pairs.d.ts +6 -3
  101. package/palindrome.d.ts +19 -6
  102. package/palindrome.js +2 -2
  103. package/partition-by.d.ts +4 -2
  104. package/partition-of.d.ts +5 -3
  105. package/partition-sort.d.ts +10 -4
  106. package/partition-sync.d.ts +15 -6
  107. package/partition-sync.js +10 -14
  108. package/partition-time.d.ts +5 -3
  109. package/partition-when.d.ts +4 -2
  110. package/partition.d.ts +11 -5
  111. package/peek.d.ts +5 -3
  112. package/permutations.d.ts +21 -9
  113. package/pluck.d.ts +4 -2
  114. package/push-sort.d.ts +1 -1
  115. package/push-sort.js +2 -2
  116. package/push.d.ts +4 -1
  117. package/push.js +2 -2
  118. package/range-nd.d.ts +13 -5
  119. package/rechunk.d.ts +9 -6
  120. package/rechunk.js +2 -4
  121. package/reduce.d.ts +6 -6
  122. package/reduce.js +13 -13
  123. package/reductions.d.ts +1 -1
  124. package/reductions.js +2 -2
  125. package/repeat.d.ts +4 -2
  126. package/repeatedly.d.ts +7 -3
  127. package/repeatedly2d.d.ts +4 -2
  128. package/repeatedly3d.d.ts +4 -2
  129. package/reverse.d.ts +4 -2
  130. package/run.d.ts +10 -10
  131. package/sample.d.ts +4 -2
  132. package/scan.d.ts +20 -16
  133. package/select-keys.d.ts +5 -3
  134. package/sliding-window.d.ts +9 -3
  135. package/sliding-window.js +1 -2
  136. package/some.d.ts +2 -2
  137. package/some.js +1 -2
  138. package/step.d.ts +32 -17
  139. package/str.d.ts +7 -1
  140. package/str.js +2 -2
  141. package/stream-shuffle.d.ts +7 -3
  142. package/stream-sort.d.ts +6 -4
  143. package/struct.d.ts +14 -7
  144. package/sub.d.ts +2 -2
  145. package/sub.js +2 -2
  146. package/swizzle.d.ts +10 -4
  147. package/symmetric.d.ts +13 -3
  148. package/take-last.d.ts +4 -2
  149. package/take-nth.d.ts +4 -2
  150. package/take-while.d.ts +4 -2
  151. package/take.d.ts +8 -3
  152. package/toggle.d.ts +7 -3
  153. package/transduce.d.ts +6 -6
  154. package/transduce.js +4 -4
  155. package/tween.d.ts +22 -18
  156. package/tween.js +2 -4
  157. package/zip.d.ts +9 -5
package/CHANGELOG.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Change Log
2
2
 
3
- - **Last updated**: 2024-04-25T19:44:55Z
3
+ - **Last updated**: 2024-06-21T19:34:38Z
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
  [![Mastodon Follow](https://img.shields.io/mastodon/follow/109331703950160316?domain=https%3A%2F%2Fmastodon.thi.ng&style=social)](https://mastodon.thi.ng/@toxi)
8
8
 
9
9
  > [!NOTE]
10
- > This is one of 192 standalone projects, maintained as part
10
+ > This is one of 193 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
  >
@@ -151,7 +151,7 @@ For Node.js REPL:
151
151
  const tx = await import("@thi.ng/transducers");
152
152
  ```
153
153
 
154
- Package sizes (brotli'd, pre-treeshake): ESM: 8.89 KB
154
+ Package sizes (brotli'd, pre-treeshake): ESM: 8.95 KB
155
155
 
156
156
  ## Dependencies
157
157
 
@@ -185,6 +185,9 @@ directory are using this package:
185
185
  | <img src="https://raw.githubusercontent.com/thi-ng/umbrella/develop/assets/examples/ellipse-proximity.png" width="240"/> | Interactive visualization of closest points on ellipses | [Demo](https://demo.thi.ng/umbrella/ellipse-proximity/) | [Source](https://github.com/thi-ng/umbrella/tree/develop/examples/ellipse-proximity) |
186
186
  | <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
187
  | <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
+ | <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) |
189
+ | <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) |
190
+ | <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) |
188
191
  | <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) |
189
192
  | <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) |
190
193
  | <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(xs: Iterable<number>): number;
7
- export declare function add(init: number, xs: Iterable<number>): 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
@@ -1,6 +1,6 @@
1
- import { __mathop } from "./internal/mathop.js";
1
+ import { __mathOp } from "./internal/mathop.js";
2
2
  function add(...args) {
3
- return __mathop(add, (acc, x) => acc + x, 0, args);
3
+ return __mathOp(add, (acc, x) => acc + x, 0, args);
4
4
  }
5
5
  export {
6
6
  add
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
- * transduce(new Mul(11), push(), range(4))
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>(xs: Iterable<Pair<A, B>>): Map<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(xs) {
3
- return xs ? reduce(assocMap(), xs) : reducer(
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>(xs: Iterable<Pair<PropertyKey, T>>): IObjectOf<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
@@ -1,6 +1,6 @@
1
1
  import { reduce, reducer } from "./reduce.js";
2
- function assocObj(xs) {
3
- return xs ? reduce(assocObj(), xs) : reducer(
2
+ function assocObj(src) {
3
+ return src ? reduce(assocObj(), src) : reducer(
4
4
  () => ({}),
5
5
  (acc, [k, v]) => (acc[k] = v, acc)
6
6
  );
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
- * autoObj("id", ["foo", "bar", "baz"])
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, xs: Iterable<T>): IObjectOf<T>;
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, xs) {
2
+ function autoObj(prefix, src) {
3
3
  let id = 0;
4
- return xs ? reduce(autoObj(prefix), xs) : reducer(
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(1000).subscribe(
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
- * [...iterator(comp(map((x) => [x, x]), cat()), [1, 2, 3, 4])]
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
- * [...iterator(
27
- * comp(
28
- * mapIndexed((i, x) => [[i], [x, x]]),
29
- * cat(),
30
- * cat()
31
- * ),
32
- * "abc"
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
- * [...mapcat((x)=>(x > 1 ? reduced([x, x]) : [x, x]), [1, 2, 3, 4])]
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>>, T>;
48
+ export declare const cat: <T>() => Transducer<MaybeReduced<Nullable<Iterable<T>>>, T>;
43
49
  //# sourceMappingURL=cat.d.ts.map
package/cat.js CHANGED
@@ -4,7 +4,7 @@ const cat = () => (rfn) => {
4
4
  const r = rfn[2];
5
5
  return compR(rfn, (acc, x) => {
6
6
  if (x) {
7
- for (let y of unreduced(x)) {
7
+ for (let y of unreduced(x) || []) {
8
8
  acc = r(acc, y);
9
9
  if (isReduced(acc)) {
10
10
  break;
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
- * transduce(take(1000), frequencies(), choices("abcd", [1, 0.5, 0.25, 0.125]))
16
- * // Map { 'c' => 132, 'a' => 545, 'b' => 251, 'd' => 72 }
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
- * [...concat([1, 2, 3], null, [4, 5])]
11
+ * console.log(
12
+ * [...concat([1, 2, 3], null, [4, 5])]
13
+ * );
12
14
  * // [ 1, 2, 3, 4, 5 ]
13
15
  *
14
- * [...concat([1, 2, 3, undefined], null, [4, 5])]
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 xs -
22
+ * @param sources -
19
23
  */
20
- export declare function concat<T>(...xs: Nullable<Iterable<T>>[]): IterableIterator<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(...xs) {
3
- for (let x of xs) {
4
- x != null && (yield* ensureIterable(x));
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>(xs: Iterable<T>): Set<T>;
6
+ export declare function conj<T>(src: Iterable<T>): Set<T>;
7
7
  //# sourceMappingURL=conj.d.ts.map
package/conj.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { reduce, reducer } from "./reduce.js";
2
- function conj(xs) {
3
- return xs ? reduce(conj(), xs) : reducer(
2
+ function conj(src) {
3
+ return src ? reduce(conj(), src) : reducer(
4
4
  () => /* @__PURE__ */ new Set(),
5
5
  (acc, x) => acc.add(x)
6
6
  );
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
- * consume(repeatedly2d((x, y) => console.log("output:", [x, y]), 2, 3));
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/consume.js CHANGED
@@ -1,6 +1,5 @@
1
1
  const consume = (src) => {
2
- for (let _ of src)
3
- ;
2
+ for (let _ of src) ;
4
3
  };
5
4
  export {
6
5
  consume
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 kernelLookup1d = (src, x, width, wrap, border) => wrap ? ({ 0: w, 1: ox }) => {
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 kernelLookup2d = (src, x, y, width, height, wrap, border) => wrap ? ({ 0: w, 1: { 0: ox, 1: oy } }) => {
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 kernelError = () => illegalArgs(`no kernel or kernel config`);
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) && kernelError();
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(kernelLookup1d(src, p, width, wrap, border)),
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) && kernelError();
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(kernelLookup2d(src, p[0], p[1], width, height, wrap, border)),
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(xs: Iterable<any>): number;
11
- export declare function count(offset: number, xs: Iterable<any>): number;
12
- export declare function count(offset: number, step: number, xs: Iterable<any>): 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
- * [...curve(50, 100, 10, 2)]
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
- * [...take(5, cycle([1, 2, 3]))]
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
- * [...cycle(range(3), 2)]
20
+ * console.log(
21
+ * [...cycle(range(3), 2)]
22
+ * );
19
23
  * // [ 0, 1, 2, 0, 1, 2 ]
20
24
  * ```
21
25
  *
package/cycle.js CHANGED
@@ -1,6 +1,5 @@
1
1
  function* cycle(input, num = Infinity) {
2
- if (num < 1)
3
- return;
2
+ if (num < 1) return;
4
3
  let cache = [];
5
4
  for (let i of input) {
6
5
  cache.push(i);
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
- * [...dedupe([1, 1, 2, 3, 3, 3, 1])]
14
+ * console.log(
15
+ * [...dedupe([1, 1, 2, 3, 3, 3, 1])]
16
+ * );
15
17
  * // [ 1, 2, 3, 1 ]
16
18
  * ```
17
19
  *
@@ -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,18 +50,19 @@ import type { TransformSpec } from "./api.js";
50
50
  * ];
51
51
  *
52
52
  * // build transformer & apply to src
53
- * deepTransform(spec)(src);
54
- *
53
+ * console.log(
54
+ * deepTransform(spec)(src)
55
+ * );
55
56
  * // [ "div",
56
- * // { class: "article" },
57
+ * // { class: "post" },
57
58
  * // [ "h1", "Hello world" ],
58
59
  * // [ "div.meta",
59
60
  * // [ "a", { href: "mailto:a@.b.com" }, "Alice" ],
60
- * // "./2/2003, 12:34:56 PM)" ],
61
+ * // "(1/2/2003, 12:34:56 PM)" ],
61
62
  * // "Ratione necessitatibus doloremque itaque." ]
62
63
  * ```
63
64
  *
64
65
  * @param spec - transformation spec
65
66
  */
66
- export declare const deepTransform: (spec: TransformSpec) => (x: any) => any;
67
+ export declare const deepTransform: (spec: TransformSpec) => ((x: any) => any);
67
68
  //# sourceMappingURL=deep-transform.d.ts.map
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
- * [...distinct({ key: (x) => x.id }, [{id: 1, x: 2}, {id: 1, x: 3}])]
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, xs: Iterable<number>): number;
7
+ export declare function div(init: number, src: Iterable<number>): number;
8
8
  //# sourceMappingURL=div.d.ts.map