@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/dup.d.ts CHANGED
@@ -7,12 +7,17 @@
7
7
  * {@link repeatedly} for achieving a different kinds of value duplication.
8
8
  *
9
9
  * @example
10
- * ```ts
11
- * import { dup } from "@thi.ng/transducers";
10
+ * ```ts tangle:../export/dup.ts
11
+ * import { dup, range } from "@thi.ng/transducers";
12
12
  *
13
- * dup("hello"); // "hellohello"
14
- * dup([1, 2, 3]); // [1, 2, 3, 1, 2, 3]
15
- * dup(range(3)); // IterableIterator<number>
13
+ * console.log(dup("hello"));
14
+ * // "hellohello"
15
+ *
16
+ * console.log(dup([1, 2, 3]));
17
+ * // [ 1, 2, 3, 1, 2, 3 ]
18
+ *
19
+ * console.log([...dup(range(3))]);
20
+ * // [ 0, 1, 2, 0, 1, 2 ]
16
21
  * ```
17
22
  *
18
23
  * @param x -
package/every.d.ts CHANGED
@@ -9,16 +9,18 @@ import type { Reducer } from "./api.js";
9
9
  * Returns true if *all* values passed test.
10
10
  *
11
11
  * @example
12
- * ```ts
12
+ * ```ts tangle:../export/every.ts
13
13
  * import { every } from "@thi.ng/transducers";
14
14
  *
15
- * every((x)=> x > 0, [1,2,-1,3]);
15
+ * console.log(
16
+ * every((x)=> x > 0, [1,2,-1,3])
17
+ * );
16
18
  * // false
17
19
  * ```
18
20
  *
19
21
  * @param pred -
20
22
  */
21
23
  export declare function every<T>(pred?: Predicate<T>): Reducer<boolean, T>;
22
- export declare function every<T>(xs: Iterable<T>): boolean;
23
- export declare function every<T>(pred: Predicate<T>, xs: Iterable<T>): boolean;
24
+ export declare function every<T>(src: Iterable<T>): boolean;
25
+ export declare function every<T>(pred: Predicate<T>, src: Iterable<T>): boolean;
24
26
  //# sourceMappingURL=every.d.ts.map
package/every.js CHANGED
@@ -2,9 +2,7 @@ import { $$reduce, reducer } from "./reduce.js";
2
2
  import { reduced } from "./reduced.js";
3
3
  function every(...args) {
4
4
  const res = $$reduce(every, args);
5
- if (res !== void 0) {
6
- return res;
7
- }
5
+ if (res !== void 0) return res;
8
6
  const pred = args[0];
9
7
  return reducer(
10
8
  () => true,
package/extend-sides.d.ts CHANGED
@@ -7,17 +7,25 @@
7
7
  * either of them to zero. `numRight` defaults to same value as
8
8
  * `numLeft`.
9
9
  *
10
+ * Also see {@link padSides}, {@link wrapSides}.
11
+ *
10
12
  * @example
11
- * ```ts
13
+ * ```ts tangle:../export/extend-sides.ts
12
14
  * import { extendSides } from "@thi.ng/transducers";
13
15
  *
14
- * [...extendSides([1, 2, 3])]
16
+ * console.log(
17
+ * [...extendSides([1, 2, 3])]
18
+ * );
15
19
  * // [ 1, 1, 2, 3, 3]
16
20
  *
17
- * [...extendSides([1, 2, 3], 3)]
21
+ * console.log(
22
+ * [...extendSides([1, 2, 3], 3)]
23
+ * );
18
24
  * // [ 1, 1, 1, 1, 2, 3, 3, 3, 3 ]
19
25
  *
20
- * [...extendSides([1, 2, 3], 0, 3)]
26
+ * console.log(
27
+ * [...extendSides([1, 2, 3], 0, 3)]
28
+ * );
21
29
  * // [ 1, 2, 3, 3, 3, 3 ]
22
30
  * ```
23
31
  *
package/fill.d.ts CHANGED
@@ -8,14 +8,14 @@ import type { Reducer } from "./api.js";
8
8
  * @param start -
9
9
  */
10
10
  export declare function fill<T>(start?: number): Reducer<T, T[]>;
11
- export declare function fill<T>(xs: Iterable<T>): T[];
12
- export declare function fill<T>(start: number, xs: Iterable<T>): T[];
11
+ export declare function fill<T>(src: Iterable<T>): T[];
12
+ export declare function fill<T>(start: number, src: Iterable<T>): T[];
13
13
  /**
14
14
  * Like {@link fill} reducer, but for numeric arrays (incl. typed arrays).
15
15
  *
16
16
  * @param start -
17
17
  */
18
18
  export declare function fillN(start?: number): Reducer<number, NumericArray>;
19
- export declare function fillN(xs: Iterable<number>): NumericArray;
20
- export declare function fillN(start: number, xs: Iterable<number>): NumericArray;
19
+ export declare function fillN(src: Iterable<number>): NumericArray;
20
+ export declare function fillN(start: number, src: Iterable<number>): NumericArray;
21
21
  //# sourceMappingURL=fill.d.ts.map
package/fill.js CHANGED
@@ -1,9 +1,7 @@
1
1
  import { $$reduce, reducer } from "./reduce.js";
2
2
  function fill(...args) {
3
3
  const res = $$reduce(fill, args);
4
- if (res !== void 0) {
5
- return res;
6
- }
4
+ if (res !== void 0) return res;
7
5
  let start = args[0] || 0;
8
6
  return reducer(
9
7
  () => [],
package/filter-fuzzy.d.ts CHANGED
@@ -23,10 +23,12 @@ export interface FilterFuzzyOpts<A, B> {
23
23
  * default.
24
24
  *
25
25
  * @example
26
- * ```ts
26
+ * ```ts tangle:../export/filter-fuzzy.ts
27
27
  * import { filterFuzzy } from "@thi.ng/transducers";
28
28
  *
29
- * [...filterFuzzy("ho", ["hello", "hallo", "hey", "heyoka"])]
29
+ * console.log(
30
+ * [...filterFuzzy("ho", ["hello", "hallo", "hey", "heyoka"])]
31
+ * );
30
32
  * // ["hello", "hallo", "heyoka"]
31
33
  * ```
32
34
  *
package/flatten-with.d.ts CHANGED
@@ -13,8 +13,9 @@ export type MaybeIterable<T> = Nullable<Iterable<T>>;
13
13
  * of results.
14
14
  *
15
15
  * @example
16
- * ```ts
17
- * import { flattenWith } from "@thi.ng/transducers";
16
+ * ```ts tangle:../export/flatten-with.ts
17
+ * import { isPlainObject, isNotStringAndIterable } from "@thi.ng/checks";
18
+ * import { flattenWith, pairs } from "@thi.ng/transducers";
18
19
  *
19
20
  * // custom predicate which converts objects into key/val tuples,
20
21
  * // returns iterables as is and null for everything else
@@ -25,7 +26,9 @@ export type MaybeIterable<T> = Nullable<Iterable<T>>;
25
26
  * ? x
26
27
  * : null;
27
28
  *
28
- * [...flattenWith(pred, [{ a: 1, b: 2 }, [[{ c: 3 }]]])]
29
+ * console.log(
30
+ * [...flattenWith(pred, [{ a: 1, b: 2 }, [[{ c: 3 }]]])]
31
+ * );
29
32
  * // [ 'a', 1, 'b', 2, 'c', 3 ]
30
33
  * ```
31
34
  *
package/flatten.d.ts CHANGED
@@ -9,13 +9,17 @@ import type { Transducer } from "./api.js";
9
9
  * iterator of results.
10
10
  *
11
11
  * @example
12
- * ```ts
12
+ * ```ts tangle:../export/flatten.ts
13
13
  * import { flatten } from "@thi.ng/transducers";
14
14
  *
15
- * [...flatten([[1, [2, 3]], ["abc", "cde"]])]
15
+ * console.log(
16
+ * [...flatten([[1, [2, 3]], ["abc", "cde"]])]
17
+ * );
16
18
  * // [1, 2, 3, "abc", "def"]
17
19
  *
18
- * [...flatten("abc")]
20
+ * console.log(
21
+ * [...flatten("abc")]
22
+ * );
19
23
  * // [ 'abc' ]
20
24
  * ```
21
25
  */
package/flatten1.d.ts CHANGED
@@ -5,18 +5,24 @@ import type { Transducer } from "./api.js";
5
5
  * 1st level of nesting in input. See {@link mapcat}.
6
6
  *
7
7
  * @example
8
- * ```ts
9
- * import { flatten1 } from "@thi.ng/transducers";
8
+ * ```ts tangle:../export/flatten1.ts
9
+ * import { flatten1, mapcat } from "@thi.ng/transducers";
10
10
  *
11
- * [...flatten1([[1], [2, 2], [3, 3, 3]])]
11
+ * console.log(
12
+ * [...flatten1([[1], [2, 2], [3, 3, 3]])]
13
+ * );
12
14
  * // [ 1, 2, 2, 3, 3, 3 ]
13
15
  *
14
16
  * // same as:
15
- * [...mapcat((x) => x, [[1], [2, 2], [3, 3, 3]])]
17
+ * console.log(
18
+ * [...mapcat((x) => x, [[1], [2, 2], [3, 3, 3]])]
19
+ * );
16
20
  * // [ 1, 2, 2, 3, 3, 3 ]
17
21
  *
18
22
  * // nullish inputs will be removed
19
- * [...flatten1([[1], null, [3, 3, 3]])]
23
+ * console.log(
24
+ * [...flatten1([[1], null, [3, 3, 3]])]
25
+ * );
20
26
  * // [1, 3, 3, 3]
21
27
  * ```
22
28
  */
package/frequencies.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import type { Fn } from "@thi.ng/api";
2
2
  import type { Reducer } from "./api.js";
3
3
  export declare function frequencies<A>(): Reducer<A, Map<A, number>>;
4
- export declare function frequencies<A>(xs: Iterable<A>): Map<A, number>;
4
+ export declare function frequencies<A>(src: Iterable<A>): Map<A, number>;
5
5
  export declare function frequencies<A, B>(key: Fn<A, B>): Reducer<A, Map<B, number>>;
6
- export declare function frequencies<A, B>(key: Fn<A, B>, xs: Iterable<A>): Map<B, number>;
6
+ export declare function frequencies<A, B>(key: Fn<A, B>, src: Iterable<A>): Map<B, number>;
7
7
  //# sourceMappingURL=frequencies.d.ts.map
package/group-binary.d.ts CHANGED
@@ -17,58 +17,68 @@ import type { Reducer } from "./api.js";
17
17
  * Index by lowest 4-bits of ID value:
18
18
  *
19
19
  * @example
20
- * ```ts
20
+ * ```ts tangle:../export/group-binary.ts
21
21
  * import { groupBinary, reduce } from "@thi.ng/transducers";
22
22
  *
23
- * tree = reduce(
24
- * groupBinary(4, x => x.id & 0xf),
25
- * [{id: 3}, {id: 8}, {id: 15}, {id: 0}]
26
- * )
23
+ * const tree = reduce(
24
+ * groupBinary<{ id: number }>(4, x => x.id & 0xf),
25
+ * [{ id: 3 }, { id: 8 }, { id: 15 }, { id: 0 }]
26
+ * );
27
27
  *
28
- * tree.l.l.l.l
28
+ * console.log(tree.l.l.l.l);
29
29
  * // [ { id: 0 } ]
30
- * tree.r.r.r.r
30
+ *
31
+ * console.log(tree.r.r.r.r);
31
32
  * // [ { id: 15 } ]
32
- * tree.l.l.r.r
33
+ *
34
+ * console.log(tree.l.l.r.r);
33
35
  * // [ { id: 3 } ]
34
36
  * ```
35
37
  *
36
38
  * Collecting as array:
37
39
  *
38
40
  * @example
39
- * ```ts
40
- * import { groupBinary, identity, push, reduce } from "@thi.ng/transducers";
41
+ * ```ts tangle:../export/group-binary-2.ts
42
+ * import { groupBinary, reduce } from "@thi.ng/transducers";
41
43
  *
42
- * tree = reduce(
43
- * groupBinary(4, identity, () => [], push(), 0, 1),
44
+ * const tree = reduce(
45
+ * groupBinary<number>(4, (x) => x, undefined, undefined, 0, 1),
44
46
  * [1, 2, 3, 4, 5, 6, 7]
45
- * )
47
+ * );
46
48
  *
47
- * tree[0][1][0][1] // 0101 == 5 in binary
49
+ * console.log(tree[0][1][0][1]); // 0101 == 5 in binary
48
50
  * // [ 5 ]
49
51
  *
50
- * tree[0][1][1] // 011* == branch
52
+ * console.log(tree[0][1][1]); // 011* == branch
51
53
  * // [ [ 6 ], [ 7 ] ]
52
54
  * ```
53
55
  *
54
56
  * Using {@link frequencies} as leaf reducer:
55
57
  *
56
58
  * @example
57
- * ```ts
59
+ * ```ts tangle:../export/group-binary-3.ts
58
60
  * import { frequencies, groupBinary, reduce } from "@thi.ng/transducers";
59
61
  *
60
- * tree = reduce(
61
- * groupBinary(3, (x: string) => x.length, null, frequencies()),
62
+ * const tree = reduce(
63
+ * groupBinary<string>(3, (x) => x.length, undefined, frequencies()),
62
64
  * "aa bbb dddd ccccc bbb eeee fff".split(" ")
63
- * )
64
- * // [ [ undefined,
65
- * // [ Map { 'aa' => 1 },
66
- * // Map { 'bbb' => 2, 'fff' => 1 } ] ],
67
- * // [ [ Map { 'dddd' => 1, 'eeee' => 1 },
68
- * // Map { 'ccccc' => 1 } ] ] ]
69
- *
70
- * tree[0][1][1]
71
- * // Map { 'bbb' => 2, 'fff' => 1 }
65
+ * );
66
+ *
67
+ * console.log(tree);
68
+ * // {
69
+ * // l: {
70
+ * // r: {
71
+ * // l: Map(1) { "aa": 1 },
72
+ * // r: Map(2) { "bbb": 2, "fff": 1 },
73
+ * // },
74
+ * // },
75
+ * // r: {
76
+ * // l: {
77
+ * // l: Map(2) { "dddd": 1, "eeee": 1 },
78
+ * // r: Map(1) { "ccccc": 1 },
79
+ * // },
80
+ * // },
81
+ * // }
72
82
  * ```
73
83
  *
74
84
  * @param bits - index range (always from 0)
package/group-binary.js CHANGED
@@ -1,15 +1,15 @@
1
1
  import { groupByObj } from "./group-by-obj.js";
2
2
  import { push } from "./push.js";
3
- const branchPred = (key, b, l, r) => (x) => key(x) & b ? r : l;
3
+ const __branchPred = (key, b, l, r) => (x) => key(x) & b ? r : l;
4
4
  const groupBinary = (bits, key, branch, leaf, left = "l", right = "r") => {
5
5
  const init = branch || (() => ({}));
6
6
  let rfn = groupByObj({
7
- key: branchPred(key, 1, left, right),
7
+ key: __branchPred(key, 1, left, right),
8
8
  group: leaf || push()
9
9
  });
10
10
  for (let i = 2, maxIndex = 1 << bits; i < maxIndex; i <<= 1) {
11
11
  rfn = groupByObj({
12
- key: branchPred(key, i, left, right),
12
+ key: __branchPred(key, i, left, right),
13
13
  group: [init, rfn[1], rfn[2]]
14
14
  });
15
15
  }
package/group-by-map.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import type { GroupByOpts, Reducer } from "./api.js";
2
2
  export declare function groupByMap<SRC, KEY, GROUP>(opts?: Partial<GroupByOpts<SRC, KEY, GROUP>>): Reducer<SRC, Map<KEY, GROUP>>;
3
- export declare function groupByMap<SRC, GROUP>(xs: Iterable<SRC>): Map<SRC, GROUP>;
4
- export declare function groupByMap<SRC, KEY, GROUP>(opts: Partial<GroupByOpts<SRC, KEY, GROUP>>, xs: Iterable<SRC>): Map<KEY, GROUP>;
3
+ export declare function groupByMap<SRC, GROUP>(src: Iterable<SRC>): Map<SRC, GROUP>;
4
+ export declare function groupByMap<SRC, KEY, GROUP>(opts: Partial<GroupByOpts<SRC, KEY, GROUP>>, src: Iterable<SRC>): Map<KEY, GROUP>;
5
5
  //# sourceMappingURL=group-by-map.d.ts.map
package/group-by-obj.d.ts CHANGED
@@ -1,6 +1,58 @@
1
1
  import type { IObjectOf } from "@thi.ng/api";
2
2
  import type { GroupByOpts, Reducer } from "./api.js";
3
+ /**
4
+ * Reducer. Groups inputs, optionally by given key fn and custom reducer. By
5
+ * default the values are used as key directly and {@link push} is used as
6
+ * default reducer.
7
+ *
8
+ * @example
9
+ * ```ts tangle:../export/group-by-obj.ts
10
+ * import { groupByObj } from "@thi.ng/transducers";
11
+ *
12
+ * console.log(
13
+ * groupByObj(
14
+ * // group items by first char
15
+ * { key: (x) => x[0] },
16
+ * ["alma", "charlie", "brontë", "anna", "cora", "aurora"]
17
+ * )
18
+ * );
19
+ * // {
20
+ * // a: [ "alma", "anna", "aurora" ],
21
+ * // c: [ "charlie", "cora" ],
22
+ * // b: [ "brontë" ],
23
+ * // }
24
+ * ```
25
+ *
26
+ * @example
27
+ * ```ts tangle:../export/group-by-obj-2.ts
28
+ * import { conj, groupByObj, repeatedly } from "@thi.ng/transducers";
29
+ *
30
+ * console.log(
31
+ * groupByObj(
32
+ * {
33
+ * // bin items by multiples of 10
34
+ * key: (x) => Math.floor(x / 10) * 10,
35
+ * // keep only uniques (using conj reducer)
36
+ * group: conj(),
37
+ * },
38
+ * repeatedly(() => Math.floor(Math.random() * 100), 20)
39
+ * )
40
+ * );
41
+ * // {
42
+ * // "0": Set(1) { 8 },
43
+ * // "10": Set(1) { 13 },
44
+ * // "20": Set(2) { 24, 22 },
45
+ * // "30": Set(2) { 38, 36 },
46
+ * // "50": Set(5) { 54, 53, 52, 56, 59 },
47
+ * // "60": Set(2) { 63, 60 },
48
+ * // "70": Set(4) { 79, 71, 74, 78 },
49
+ * // "80": Set(2) { 85, 81 },
50
+ * // }
51
+ * ```
52
+ *
53
+ * @param opts
54
+ */
3
55
  export declare function groupByObj<SRC, GROUP>(opts?: Partial<GroupByOpts<SRC, PropertyKey, GROUP>>): Reducer<SRC, IObjectOf<GROUP>>;
4
- export declare function groupByObj<SRC>(xs: Iterable<SRC>): IObjectOf<SRC[]>;
5
- export declare function groupByObj<SRC, GROUP>(opts: Partial<GroupByOpts<SRC, PropertyKey, GROUP>>, xs: Iterable<SRC>): IObjectOf<GROUP>;
56
+ export declare function groupByObj<SRC>(src: Iterable<SRC>): IObjectOf<SRC[]>;
57
+ export declare function groupByObj<SRC, GROUP>(opts: Partial<GroupByOpts<SRC, PropertyKey, GROUP>>, src: Iterable<SRC>): IObjectOf<GROUP>;
6
58
  //# sourceMappingURL=group-by-obj.d.ts.map
@@ -10,5 +10,15 @@ import type { Reducer, ReductionFn } from "../api.js";
10
10
  *
11
11
  * @internal
12
12
  */
13
- export declare const __mathop: (rfn: FnAny<Reducer<number, number>>, fn: ReductionFn<number, number>, initDefault: number, args: any[]) => any;
13
+ export declare const __mathOp: (rfn: FnAny<Reducer<number, number>>, fn: ReductionFn<number, number>, initDefault: number, args: any[]) => any;
14
+ /**
15
+ * Shared impl for {@link minCompare} & {@link maxCompare}.
16
+ *
17
+ * @param rfn
18
+ * @param args
19
+ * @param sign
20
+ *
21
+ * @internal
22
+ */
23
+ export declare const __compareOp: (rfn: FnAny<Reducer<any, any>>, args: any[], sign: 1 | -1) => any;
14
24
  //# sourceMappingURL=mathop.d.ts.map
@@ -1,12 +1,19 @@
1
+ import { compare } from "@thi.ng/compare/compare";
1
2
  import { $$reduce, reducer } from "../reduce.js";
2
- const __mathop = (rfn, fn, initDefault, args) => {
3
+ const __mathOp = (rfn, fn, initDefault, args) => {
3
4
  const res = $$reduce(rfn, args);
4
- if (res !== void 0) {
5
- return res;
6
- }
5
+ if (res !== void 0) return res;
7
6
  const init = args[0] || initDefault;
8
7
  return reducer(() => init, fn);
9
8
  };
9
+ const __compareOp = (rfn, args, sign) => {
10
+ const res = $$reduce(rfn, args);
11
+ if (res !== void 0) return res;
12
+ const init = args[0];
13
+ const cmp = args[1] || compare;
14
+ return reducer(init, (acc, x) => sign * cmp(acc, x) >= 0 ? acc : x);
15
+ };
10
16
  export {
11
- __mathop
17
+ __compareOp,
18
+ __mathOp
12
19
  };
package/interpolate.d.ts CHANGED
@@ -21,16 +21,17 @@ import type { Transducer } from "./api.js";
21
21
  * - {@link extendSides}
22
22
  *
23
23
  * @example
24
- * ```ts
24
+ * ```ts tangle:../export/interpolate.ts
25
25
  * import { interpolate } from "@thi.ng/transducers";
26
26
  *
27
- * [...interpolate(
27
+ * const res = [...interpolate(
28
28
  * ([a, b], t) => a + (b - a) * t,
29
29
  * 2,
30
30
  * 8,
31
31
  * [0, 1, 0, 2]
32
- * )]
32
+ * )];
33
33
  *
34
+ * console.log(res);
34
35
  * // [ 0, 0.125, 0.25, 0.375, 0.5, 0.625, 0.75, 0.875,
35
36
  * // 1, 0.875, 0.75, 0.625, 0.5, 0.375, 0.25, 0.125,
36
37
  * // 0, 0.25, 0.5, 0.75, 1, 1.25, 1.5, 1.75 ]
package/iterate.d.ts CHANGED
@@ -10,13 +10,17 @@ import type { Fn2 } from "@thi.ng/api";
10
10
  * iteration counter as 2nd arg (starting w/ i=1).
11
11
  *
12
12
  * @example
13
- * ```ts
13
+ * ```ts tangle:../export/iterate.ts
14
14
  * import { iterate } from "@thi.ng/transducers";
15
15
  *
16
- * [...iterate((x) => x * 2, 1, 5)]
16
+ * console.log(
17
+ * [...iterate((x) => x * 2, 1, 5)]
18
+ * );
17
19
  * // [ 1, 2, 4, 8, 16 ]
18
20
  *
19
- * [...iterate((x, i) => x * 10 + i, 0, 8)]
21
+ * console.log(
22
+ * [...iterate((x, i) => x * 10 + i, 0, 8)]
23
+ * );
20
24
  * // [ 0, 1, 12, 123, 1234, 12345, 123456, 1234567 ]
21
25
  * ```
22
26
  *
package/iterator.d.ts CHANGED
@@ -5,9 +5,9 @@ import type { Transducer, TxLike } from "./api.js";
5
5
  * transformed results.
6
6
  *
7
7
  * @param xform -
8
- * @param xs -
8
+ * @param src -
9
9
  */
10
- export declare function iterator<A, B>(xform: TxLike<A, B>, xs: Iterable<A>): IterableIterator<B>;
10
+ export declare function iterator<A, B>(xform: TxLike<A, B>, src: Iterable<A>): IterableIterator<B>;
11
11
  /**
12
12
  * Optimized version of {@link iterator} for transducers which are
13
13
  * guaranteed to:
@@ -16,9 +16,9 @@ export declare function iterator<A, B>(xform: TxLike<A, B>, xs: Iterable<A>): It
16
16
  * 2) Do not require a `completion` reduction step
17
17
  *
18
18
  * @param xform -
19
- * @param xs -
19
+ * @param src -
20
20
  */
21
- export declare function iterator1<A, B>(xform: TxLike<A, B>, xs: Iterable<A>): IterableIterator<B>;
21
+ export declare function iterator1<A, B>(xform: TxLike<A, B>, src: Iterable<A>): IterableIterator<B>;
22
22
  /**
23
23
  * Helper function used by various transducers to wrap themselves as
24
24
  * transforming iterators. Delegates to {@link iterator1} by default.
package/iterator.js CHANGED
@@ -3,11 +3,11 @@ import { isIterable } from "@thi.ng/checks/is-iterable";
3
3
  import { ensureTransducer } from "./ensure.js";
4
4
  import { push } from "./push.js";
5
5
  import { isReduced, unreduced } from "./reduced.js";
6
- function* iterator(xform, xs) {
6
+ function* iterator(xform, src) {
7
7
  const rfn = ensureTransducer(xform)(push());
8
8
  const complete = rfn[1];
9
9
  const reduce = rfn[2];
10
- for (let x of xs) {
10
+ for (let x of src) {
11
11
  const y = reduce([], x);
12
12
  if (isReduced(y)) {
13
13
  yield* unreduced(complete(y.deref()));
@@ -19,9 +19,9 @@ function* iterator(xform, xs) {
19
19
  }
20
20
  yield* unreduced(complete([]));
21
21
  }
22
- function* iterator1(xform, xs) {
22
+ function* iterator1(xform, src) {
23
23
  const reduce = ensureTransducer(xform)([NO_OP, NO_OP, (_, x) => x])[2];
24
- for (let x of xs) {
24
+ for (let x of src) {
25
25
  let y = reduce(SEMAPHORE, x);
26
26
  if (isReduced(y)) {
27
27
  y = unreduced(y.deref());
package/juxtr.d.ts CHANGED
@@ -11,10 +11,16 @@ import type { Reducer } from "./api.js";
11
11
  * any number of reducers.
12
12
  *
13
13
  * @example
14
- * ```ts
14
+ * ```ts tangle:../export/juxtr.ts
15
15
  * import { add, juxtR, reduce, reductions, str } from "@thi.ng/transducers";
16
16
  *
17
- * reduce(juxtR(add(), reductions(add()), str("-")), [1, 2, 3, 4]);
17
+ * console.log(
18
+ * reduce(
19
+ * // use 3 reducers in parallel
20
+ * juxtR(add(), reductions(add()), str("-")),
21
+ * [1, 2, 3, 4]
22
+ * )
23
+ * );
18
24
  * // [ 10, [ 0, 1, 3, 6, 10 ], '1-2-3-4' ]
19
25
  * ```
20
26
  */
@@ -12,10 +12,12 @@ import type { IObjectOf } from "@thi.ng/api";
12
12
  * on the VM's iteration behavior of `Object.keys()`.
13
13
  *
14
14
  * @example
15
- * ```ts
15
+ * ```ts tangle:../export/key-permutations.ts
16
16
  * import { keyPermutations } from "@thi.ng/transducers";
17
17
  *
18
- * [...keyPermutations({ a: [1, 2], b: [true, false], c: ["X", "Y"] })]
18
+ * console.log(
19
+ * [...keyPermutations({ a: [1, 2], b: [true, false], c: ["X", "Y"] })]
20
+ * );
19
21
  * // [
20
22
  * // { a: 1, b: true, c: 'X' },
21
23
  * // { a: 1, b: true, c: 'Y' },
package/last.d.ts CHANGED
@@ -1,4 +1,4 @@
1
1
  import type { Reducer } from "./api.js";
2
2
  export declare function last<T>(): Reducer<T, T>;
3
- export declare function last<T>(xs: Iterable<T>): T;
3
+ export declare function last<T>(src: Iterable<T>): T;
4
4
  //# sourceMappingURL=last.d.ts.map
package/last.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { NO_OP } from "@thi.ng/api/api";
2
2
  import { reduce, reducer } from "./reduce.js";
3
- function last(xs) {
4
- return xs ? reduce(last(), xs) : reducer(NO_OP, (_, x) => x);
3
+ function last(src) {
4
+ return src ? reduce(last(), src) : reducer(NO_OP, (_, x) => x);
5
5
  }
6
6
  export {
7
7
  last
package/length.d.ts CHANGED
@@ -6,10 +6,12 @@ import type { ILength } from "@thi.ng/api";
6
6
  * sequence of these values.
7
7
  *
8
8
  * @example
9
- * ```ts
9
+ * ```ts tangle:../export/length.ts
10
10
  * import { length } from "@thi.ng/transducers";
11
11
  *
12
- * [...length(0, ["a", "bc", "def"])]
12
+ * console.log(
13
+ * [...length(0, ["a", "bc", "def"])]
14
+ * );
13
15
  * // [1, 2, 3]
14
16
  * ```
15
17
  *
package/line.d.ts CHANGED
@@ -11,10 +11,12 @@
11
11
  * [`line()`](https://docs.thi.ng/umbrella/dsp/functions/line.html).
12
12
  *
13
13
  * @example
14
- * ```ts
14
+ * ```ts tangle:../export/line.ts
15
15
  * import { line } from "@thi.ng/transducers";
16
16
  *
17
- * [...line(50, 100, 10)]
17
+ * console.log(
18
+ * [...line(50, 100, 10)]
19
+ * );
18
20
  * // [
19
21
  * // 50, 55, 60, 65, 70,
20
22
  * // 75, 80, 85, 90, 95,