@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/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
- * [...map(lookup1d([10, 20, 30]), [2,0,1])]
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
- * [...map(lookup2d([...range(9)], 3), range2d(2, -1, 0, 3))]
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 { assocObj, mapIndexed, transduce } from "@thi.ng/transducers";
11
+ * ```ts tangle:../export/map-indexed.ts
12
+ * import { mapIndexed } from "@thi.ng/transducers";
13
13
  *
14
- * transduce(
15
- * mapIndexed((i, x) => ["id" + i, x * 10], 42),
16
- * assocObj(),
17
- * [1, 2, 3]
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
- * [...mapNth(3, (x) => x * 10, range(1,10))]
16
- * // [ 10, 2, 3, 40, 5, 6, 70, 8, 9 ]
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
- * [...mapNth(3, 5, (x) => x * 10, range(1,10))]
20
- * // [ 1, 2, 3, 4, 5, 60, 7, 8, 90 ]
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
- * [...mapVals((x)=> x * 10, [{a: 1, b: 2}, {c: 3, d: 4}])]
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
- * [...map((x) => x * 10, [1, 2, 3])]
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
- * [...mapcat((x) => [x, x], [1, 2, 3])]
13
+ * console.log(
14
+ * [...mapcat((x) => [x, x], [1, 2, 3])]
15
+ * );
14
16
  * // [ 1, 1, 2, 2, 3, 3 ]
15
17
  *
16
- * [...mapcat((x) => x > 2 ? [x, x, x] : null, [1, 2, 3])]
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>>>): Transducer<A, B>;
23
- export declare function mapcat<A, B>(fn: Fn<A, Nullable<Iterable<B>>>, src: Iterable<A>): IterableIterator<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 composition / syntax sugar for:
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 { comp, map, matchFirst, push, transduce } from "@thi.ng/transducers";
12
+ * ```ts tangle:../export/match-first.ts
13
+ * import {
14
+ * comp, map, matchFirst, push, transduce
15
+ * } from "@thi.ng/transducers";
21
16
  *
22
- * matchFirst((x) => x >= 5, [3, 1, 4, 2, 6, 5])
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 yields none or only the **last**
5
- * value which passed the predicate check. If `src` input is given, returns last
6
- * match found (or `undefined`).
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
- * matchLast((x) => x >= 5, [3, 1, 6, 5, 4, 2])
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
- * // 50
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>, xs: Iterable<T>): T;
5
- export declare function maxCompare<T>(init: Fn0<T>, cmp: Comparator<T>, xs: Iterable<T>): 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 { compare } from "@thi.ng/compare/compare";
2
- import { $$reduce, reducer } from "./reduce.js";
1
+ import { __compareOp } from "./internal/mathop.js";
3
2
  function maxCompare(...args) {
4
- const res = $$reduce(maxCompare, args);
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(xs: Iterable<number>): number;
7
+ export declare function maxMag(src: Iterable<number>): number;
8
8
  //# sourceMappingURL=max-mag.d.ts.map
package/max-mag.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { reduce, reducer } from "./reduce.js";
2
- function maxMag(xs) {
3
- return xs ? reduce(maxMag(), xs) : reducer(
2
+ function maxMag(src) {
3
+ return src ? reduce(maxMag(), src) : reducer(
4
4
  () => 0,
5
5
  (acc, x) => Math.abs(x) > Math.abs(acc) ? x : acc
6
6
  );
package/max.d.ts CHANGED
@@ -1,4 +1,4 @@
1
1
  import type { Reducer } from "./api.js";
2
2
  export declare function max(): Reducer<number, number>;
3
- export declare function max(xs: Iterable<number>): number;
3
+ export declare function max(src: Iterable<number>): number;
4
4
  //# sourceMappingURL=max.d.ts.map
package/max.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { reduce, reducer } from "./reduce.js";
2
- function max(xs) {
3
- return xs ? reduce(max(), xs) : reducer(
2
+ function max(src) {
3
+ return src ? reduce(max(), src) : reducer(
4
4
  () => -Infinity,
5
5
  (acc, x) => Math.max(acc, x)
6
6
  );
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(xs: Iterable<number>): number;
7
+ export declare function mean(src: Iterable<number>): number;
8
8
  //# sourceMappingURL=mean.d.ts.map
package/mean.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { reduce } from "./reduce.js";
2
- function mean(xs) {
2
+ function mean(src) {
3
3
  let n = 1;
4
- return xs ? reduce(mean(), xs) : [
4
+ return src ? reduce(mean(), src) : [
5
5
  () => n = 0,
6
6
  (acc) => n > 1 ? acc / n : acc,
7
7
  (acc, x) => (n++, acc + x)
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>, xs: Iterable<T>): T;
5
- export declare function minCompare<T>(init: Fn0<T>, cmp: Comparator<T>, xs: Iterable<T>): 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 { compare } from "@thi.ng/compare/compare";
2
- import { $$reduce, reducer } from "./reduce.js";
1
+ import { __compareOp } from "./internal/mathop.js";
3
2
  function minCompare(...args) {
4
- const res = $$reduce(minCompare, args);
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(xs: Iterable<number>): number;
7
+ export declare function minMag(src: Iterable<number>): number;
8
8
  //# sourceMappingURL=min-mag.d.ts.map
package/min-mag.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { reduce, reducer } from "./reduce.js";
2
- function minMag(xs) {
3
- return xs ? reduce(minMag(), xs) : reducer(
2
+ function minMag(src) {
3
+ return src ? reduce(minMag(), src) : reducer(
4
4
  () => Infinity,
5
5
  (acc, x) => Math.abs(x) < Math.abs(acc) ? x : acc
6
6
  );
package/min.d.ts CHANGED
@@ -1,4 +1,4 @@
1
1
  import type { Reducer } from "./api.js";
2
2
  export declare function min(): Reducer<number, number>;
3
- export declare function min(xs: Iterable<number>): number;
3
+ export declare function min(src: Iterable<number>): number;
4
4
  //# sourceMappingURL=min.d.ts.map
package/min.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { reduce, reducer } from "./reduce.js";
2
- function min(xs) {
3
- return xs ? reduce(min(), xs) : reducer(
2
+ function min(src) {
3
+ return src ? reduce(min(), src) : reducer(
4
4
  () => Infinity,
5
5
  (acc, x) => Math.min(acc, x)
6
6
  );
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(xs: Iterable<number>): number;
8
- export declare function mul(init: number, xs: Iterable<number>): 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
@@ -1,6 +1,6 @@
1
- import { __mathop } from "./internal/mathop.js";
1
+ import { __mathOp } from "./internal/mathop.js";
2
2
  function mul(...args) {
3
- return __mathop(mul, (acc, x) => acc * x, 1, args);
3
+ return __mathOp(mul, (acc, x) => acc * x, 1, args);
4
4
  }
5
5
  export {
6
6
  mul
@@ -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
- * // [ { length: 5, upper: 'ALICE', initial: 'A' },
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
- * transduce(filter(x => x<3), normCount(items.length), items);
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, xs: Iterable<any>): 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
- * normFrequenciesAuto(items)
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
- * normFrequenciesAuto(x => x[0], ["alice", "abba", "bob", "charlie"])
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>(xs: Iterable<A>): Map<A, number>;
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>, xs: Iterable<A>): Map<B, number>;
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
@@ -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
- * normFrequencies(10, items)
17
- * // Map(5) { 1 => 0.4, 2 => 0.3, 3 => 0.1, 4 => 0.1, 5 => 0.1 }
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, xs: Iterable<A>): Map<A, 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>, xs: Iterable<A>): Map<B, number>;
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
- * [...normRange(4)]
10
+ * console.log(
11
+ * [...normRange(4)]
12
+ * );
11
13
  * // [0, 0.25, 0.5, 0.75, 1.0]
12
14
  *
13
- * [...normRange(4, false)]
15
+ * console.log(
16
+ * [...normRange(4, false)]
17
+ * );
14
18
  * // [0, 0.25, 0.5, 0.75]
15
19
  *
16
- * [...normRange(4, true, true)]
20
+ * console.log(
21
+ * [...normRange(4, true, true)]
22
+ * );
17
23
  * // [1, 0.75, 0.5, 0.25, 0]
18
24
  *
19
- * [...normRange(4, false, true)]
25
+ * console.log(
26
+ * [...normRange(4, false, true)]
27
+ * );
20
28
  * // [1, 0.75, 0.5, 0.25]
21
29
  * ```
22
30
  *