@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.
Files changed (146) hide show
  1. package/CHANGELOG.md +9 -1
  2. package/README.md +4 -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/converge.d.ts +5 -3
  22. package/convolve.js +7 -7
  23. package/count.d.ts +3 -3
  24. package/curve.d.ts +6 -4
  25. package/cycle.d.ts +7 -3
  26. package/dedupe.d.ts +4 -2
  27. package/deep-transform.d.ts +9 -8
  28. package/distinct.d.ts +4 -2
  29. package/div.d.ts +1 -1
  30. package/div.js +2 -2
  31. package/dup.d.ts +10 -5
  32. package/every.d.ts +6 -4
  33. package/every.js +1 -3
  34. package/extend-sides.d.ts +12 -4
  35. package/fill.d.ts +4 -4
  36. package/fill.js +1 -3
  37. package/filter-fuzzy.d.ts +4 -2
  38. package/flatten-with.d.ts +6 -3
  39. package/flatten.d.ts +7 -3
  40. package/flatten1.d.ts +11 -5
  41. package/frequencies.d.ts +2 -2
  42. package/group-binary.d.ts +37 -27
  43. package/group-binary.js +3 -3
  44. package/group-by-map.d.ts +2 -2
  45. package/group-by-obj.d.ts +54 -2
  46. package/internal/mathop.d.ts +11 -1
  47. package/internal/mathop.js +12 -5
  48. package/interpolate.d.ts +4 -3
  49. package/iterate.d.ts +7 -3
  50. package/iterator.d.ts +4 -4
  51. package/iterator.js +4 -4
  52. package/juxtr.d.ts +8 -2
  53. package/key-permutations.d.ts +4 -2
  54. package/last.d.ts +1 -1
  55. package/last.js +2 -2
  56. package/length.d.ts +4 -2
  57. package/line.d.ts +4 -2
  58. package/lookup.d.ts +8 -4
  59. package/map-indexed.d.ts +6 -8
  60. package/map-keys.d.ts +5 -3
  61. package/map-nth.d.ts +10 -6
  62. package/map-vals.d.ts +4 -2
  63. package/map.d.ts +4 -2
  64. package/mapcat.d.ts +10 -6
  65. package/match-first.d.ts +16 -17
  66. package/match-last.d.ts +12 -8
  67. package/max-compare.d.ts +3 -3
  68. package/max-compare.js +2 -9
  69. package/max-mag.d.ts +1 -1
  70. package/max-mag.js +2 -2
  71. package/max.d.ts +1 -1
  72. package/max.js +2 -2
  73. package/mean.d.ts +1 -1
  74. package/mean.js +2 -2
  75. package/min-compare.d.ts +3 -3
  76. package/min-compare.js +2 -9
  77. package/min-mag.d.ts +1 -1
  78. package/min-mag.js +2 -2
  79. package/min.d.ts +1 -1
  80. package/min.js +2 -2
  81. package/mul.d.ts +2 -2
  82. package/mul.js +2 -2
  83. package/multiplex-obj.d.ts +10 -6
  84. package/multiplex.d.ts +8 -6
  85. package/norm-count.d.ts +5 -3
  86. package/norm-frequencies-auto.d.ts +9 -5
  87. package/norm-frequencies.d.ts +13 -5
  88. package/norm-range.d.ts +13 -5
  89. package/package.json +14 -14
  90. package/pad-last.d.ts +24 -15
  91. package/pad-sides.d.ts +27 -5
  92. package/page.d.ts +13 -5
  93. package/pairs.d.ts +6 -3
  94. package/palindrome.d.ts +19 -6
  95. package/palindrome.js +2 -2
  96. package/partition-by.d.ts +4 -2
  97. package/partition-of.d.ts +5 -3
  98. package/partition-sort.d.ts +10 -4
  99. package/partition-sync.d.ts +15 -6
  100. package/partition-sync.js +6 -6
  101. package/partition-time.d.ts +5 -3
  102. package/partition-when.d.ts +4 -2
  103. package/partition.d.ts +11 -5
  104. package/peek.d.ts +5 -3
  105. package/permutations.d.ts +21 -9
  106. package/pluck.d.ts +4 -2
  107. package/push-sort.d.ts +1 -1
  108. package/push-sort.js +2 -2
  109. package/push.d.ts +4 -1
  110. package/push.js +2 -2
  111. package/range-nd.d.ts +13 -5
  112. package/rechunk.d.ts +9 -6
  113. package/reduce.d.ts +6 -6
  114. package/reduce.js +13 -13
  115. package/reductions.d.ts +1 -1
  116. package/reductions.js +2 -2
  117. package/repeat.d.ts +4 -2
  118. package/repeatedly.d.ts +7 -3
  119. package/repeatedly2d.d.ts +4 -2
  120. package/repeatedly3d.d.ts +4 -2
  121. package/reverse.d.ts +4 -2
  122. package/run.d.ts +10 -10
  123. package/sample.d.ts +4 -2
  124. package/scan.d.ts +20 -16
  125. package/select-keys.d.ts +5 -3
  126. package/sliding-window.d.ts +9 -3
  127. package/some.d.ts +2 -2
  128. package/step.d.ts +32 -17
  129. package/str.d.ts +7 -1
  130. package/str.js +2 -2
  131. package/stream-shuffle.d.ts +7 -3
  132. package/stream-sort.d.ts +6 -4
  133. package/struct.d.ts +14 -7
  134. package/sub.d.ts +2 -2
  135. package/sub.js +2 -2
  136. package/swizzle.d.ts +10 -4
  137. package/symmetric.d.ts +13 -3
  138. package/take-last.d.ts +4 -2
  139. package/take-nth.d.ts +4 -2
  140. package/take-while.d.ts +4 -2
  141. package/take.d.ts +8 -3
  142. package/toggle.d.ts +7 -3
  143. package/transduce.d.ts +6 -6
  144. package/transduce.js +4 -4
  145. package/tween.d.ts +22 -18
  146. 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
- * [...rechunk(/-/, ["abc-d", "ef-g-", "hij", "-k-lm"])]
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(xs: Iterable<string>): IterableIterator<string>;
48
- export declare function rechunk(re: RegExp, xs: Iterable<string>): IterableIterator<string>;
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>, xs: Iterable<A>): B;
4
- export declare function reduce<A, B>(rfn: Reducer<A, B>, acc: B, xs: Iterable<A>): B;
5
- export declare function reduce<A, B>(rfn: Reducer<A, B>, xs: IReducible<A, B>): B;
6
- export declare function reduce<A, B>(rfn: Reducer<A, B>, acc: A, xs: IReducible<A, B>): B;
7
- export declare function reduceRight<A, B>(rfn: Reducer<A, B>, xs: ArrayLike<A>): B;
8
- export declare function reduceRight<A, B>(rfn: Reducer<A, B>, acc: B, xs: ArrayLike<A>): 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 parseArgs = (args) => args.length === 2 ? [void 0, args[1]] : args.length === 3 ? [args[1], args[2]] : illegalArity(args.length);
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 = parseArgs(args);
13
+ args = __parseArgs(args);
14
14
  const acc = args[0] == null ? init() : args[0];
15
- const xs = args[1];
15
+ const src = args[1];
16
16
  return unreduced(
17
17
  complete(
18
- implementsFunction(xs, "$reduce") ? xs.$reduce(reduce2, acc) : isArrayLike(xs) ? reduceArray(reduce2, acc, xs) : reduceIterable(reduce2, acc, xs)
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 = parseArgs(args);
24
+ args = __parseArgs(args);
25
25
  let acc = args[0] == null ? init() : args[0];
26
- const xs = args[1];
27
- for (let i = xs.length; i-- > 0; ) {
28
- acc = reduce2(acc, xs[i]);
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 reduceArray = (rfn, acc, xs) => {
37
- for (let i = 0, n = xs.length; i < n; i++) {
38
- acc = rfn(acc, xs[i]);
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 reduceIterable = (rfn, acc, xs) => {
47
- for (let x of xs) {
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>, xs: Iterable<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, xs) {
3
+ function reductions(rfn, src) {
4
4
  const [init, complete, _reduce] = rfn;
5
- return xs ? reduce(reductions(rfn), xs) : [
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
- * [...repeat(42, 5)]
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
- * [...repeatedly(() => Math.floor(Math.random() * 10), 5)]
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
- * [...repeatedly((i) => i, 5)]
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
- * [...repeatedly2d((x, y) => [(x + 1) * 10, (y + 1) * 100], 2, 3)]
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
- * [...repeatedly3d((x, y, z) => [(x+1)*10, (y+1)*100, (z+1)*1000], 2, 2, 2)]
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
- * [...reverse("hello world")]
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 `xs` with given transducer and optional side effect
5
- * without any reduction step. If `fx` is given it will be called with
6
- * every value produced by the transducer. If `fx` is *not* given, the
7
- * transducer is assumed to include at least one {@link sideEffect} step
8
- * itself. Returns nothing.
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 xs -
11
+ * @param src -
12
12
  */
13
- export declare function run<A>(tx: TxLike<A, any>, xs: Iterable<A>): void;
14
- export declare function run<A>(tx: TxLike<A, any>, xs: IReducible<A, any>): void;
15
- export declare function run<A, B>(tx: TxLike<A, B>, fx: Fn<B, void>, xs: Iterable<A>): void;
16
- export declare function run<A, B>(tx: TxLike<A, B>, fx: Fn<B, void>, xs: IReducible<A, any>): 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
- * [...sample(0.1, range(100))]
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
- * [...iterator(scan(add()), range(10))]
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
- * [...scan(add(), 100, range(10))]
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
- * // [ 'alpha beta gamma delta', 23 ]
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
  *
@@ -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
- * [...slidingWindow(3, range(5))]
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
- * [...slidingWindow(3, false, range(5))]
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>(xs: Iterable<T>): boolean;
12
- export declare function some<T>(pred: Predicate<T>, xs: Iterable<T>): boolean;
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, macat, step, take } from "@thi.ng/transducers";
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
- * step(map(x => x * 10))(1);
18
+ * console.log(
19
+ * step(map((x: number) => x * 10))(1)
20
+ * );
19
21
  * // 10
20
22
  *
21
23
  * // single result (no unwrapping)
22
- * step(map(x => x * 10), false)(1);
24
+ * console.log(
25
+ * step(map((x: number) => x * 10), false)(1)
26
+ * );
23
27
  * // [10]
24
28
  *
25
29
  * // multiple results
26
- * step(mapcat(x => [x, x + 1, x + 2]))(1)
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
- * step(mapcat(x => x))([1, 2])
36
+ * console.log(
37
+ * step(mapcat((x: number[]) => take(2, x)))([1, 2, 3, 4])
38
+ * );
31
39
  * // [1, 2]
32
- * step(mapcat(x => x))([3])
40
+ *
41
+ * console.log(
42
+ * step(mapcat((x: number[]) => x))([3])
43
+ * );
33
44
  * // 3
45
+ *
34
46
  * // ...once more without unwrapping
35
- * step(mapcat(x => x), false)([3])
47
+ * console.log(
48
+ * step(mapcat((x: number[]) => x), false)([3])
49
+ * );
36
50
  * // [3]
37
51
  *
38
- * // no result
39
- * f = step(filter((x) => !(x & 1)))
40
- * f(1); // undefined
41
- * f(2); // 2
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
- * f = step(take(2));
45
- * f(1); // 1
46
- * f(1); // 1
47
- * f(1); // undefined
48
- * f(1); // undefined
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, xs: Iterable<any>): 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, xs) {
2
+ function str(sep, src) {
3
3
  sep = sep || "";
4
4
  let first = true;
5
- return xs ? [...xs].join(sep) : reducer(
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
  );
@@ -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
- * [...streamShuffle(5, range(10))]
33
+ * console.log(
34
+ * [...streamShuffle(5, range(10))]
35
+ * );
34
36
  * // [ 3, 2, 5, 0, 8, 7, 1, 6, 4, 9 ]
35
37
  *
36
- * [...streamShuffle({ n: 5, rnd: new XsAdd(12345) }, range(10))]
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 proper sliding
4
- * window and insertion sort instead of fully sorting window as done by
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
- * [...streamSort(4, [5,9,2,6,4,1,3,8,7,0])]
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
- * // [ { color: [ 1, 0.5, 0, 1 ],
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
- * // { color: [ 0, 0, 1, 1 ],
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(xs: Iterable<number>): number;
8
- export declare function sub(init: number, xs: Iterable<number>): 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
@@ -1,6 +1,6 @@
1
- import { __mathop } from "./internal/mathop.js";
1
+ import { __mathOp } from "./internal/mathop.js";
2
2
  function sub(...args) {
3
- return __mathop(sub, (acc, x) => acc - x, 0, args);
3
+ return __mathOp(sub, (acc, x) => acc - x, 0, args);
4
4
  }
5
5
  export {
6
6
  sub
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
- * [...swizzle([3, 0, 2, 1], [[1, 2, 3, 4], [10, 20, 30, 40]])]
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
- * [...swizzle([0, 0, 1, 1], [[1, 2, 3, 4], [10, 20, 30, 40]])]
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
- * [...swizzle(["z", "x"], [{x: 1, y: 2, z: 3}])]
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
- * [...symmetric([1, 2, 3])]
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
- * [...takeLast(3, range(10))]
10
+ * console.log(
11
+ * [...takeLast(3, range(10))]
12
+ * );
11
13
  * // [ 7, 8, 9 ]
12
14
  * ```
13
15
  *