@thi.ng/transducers 8.9.6 → 8.9.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (80) hide show
  1. package/CHANGELOG.md +1 -1
  2. package/api.d.ts +5 -0
  3. package/auto-obj.d.ts +2 -0
  4. package/cat.d.ts +5 -3
  5. package/choices.d.ts +6 -2
  6. package/compr.d.ts +2 -0
  7. package/concat.d.ts +2 -0
  8. package/consume.d.ts +2 -0
  9. package/converge.d.ts +2 -0
  10. package/curve.d.ts +2 -0
  11. package/cycle.d.ts +2 -0
  12. package/dedupe.d.ts +2 -0
  13. package/deep-transform.d.ts +4 -2
  14. package/distinct.d.ts +2 -0
  15. package/dup.d.ts +2 -0
  16. package/every.d.ts +3 -1
  17. package/extend-sides.d.ts +2 -0
  18. package/filter-fuzzy.d.ts +2 -0
  19. package/flatten-with.d.ts +2 -0
  20. package/flatten.d.ts +2 -0
  21. package/group-binary.d.ts +6 -0
  22. package/interpolate.d.ts +2 -0
  23. package/iterate.d.ts +2 -0
  24. package/juxtr.d.ts +2 -0
  25. package/key-permutations.d.ts +2 -0
  26. package/length.d.ts +2 -0
  27. package/line.d.ts +2 -0
  28. package/lookup.d.ts +4 -0
  29. package/map-indexed.d.ts +2 -0
  30. package/map-keys.d.ts +2 -0
  31. package/map-nth.d.ts +2 -0
  32. package/map-vals.d.ts +2 -0
  33. package/map.d.ts +2 -0
  34. package/match-first.d.ts +7 -2
  35. package/match-last.d.ts +6 -10
  36. package/multiplex-obj.d.ts +2 -0
  37. package/multiplex.d.ts +4 -0
  38. package/norm-count.d.ts +2 -0
  39. package/norm-frequencies-auto.d.ts +2 -0
  40. package/norm-frequencies.d.ts +5 -0
  41. package/norm-range.d.ts +2 -0
  42. package/package.json +8 -8
  43. package/pad-last.d.ts +2 -0
  44. package/pad-sides.d.ts +9 -8
  45. package/page.d.ts +2 -0
  46. package/pairs.d.ts +2 -0
  47. package/palindrome.d.ts +2 -0
  48. package/partition-by.d.ts +2 -0
  49. package/partition-of.d.ts +2 -0
  50. package/partition-sort.d.ts +2 -0
  51. package/partition-sync.d.ts +5 -0
  52. package/partition-when.d.ts +2 -0
  53. package/partition.d.ts +2 -0
  54. package/peek.d.ts +2 -0
  55. package/permutations.d.ts +4 -0
  56. package/pluck.d.ts +2 -0
  57. package/range-nd.d.ts +2 -0
  58. package/rechunk.d.ts +2 -0
  59. package/repeat.d.ts +2 -0
  60. package/repeatedly.d.ts +2 -0
  61. package/repeatedly2d.d.ts +2 -0
  62. package/repeatedly3d.d.ts +2 -0
  63. package/reverse.d.ts +3 -1
  64. package/sample.d.ts +2 -0
  65. package/scan.d.ts +4 -0
  66. package/select-keys.d.ts +2 -0
  67. package/sliding-window.d.ts +2 -0
  68. package/step.d.ts +2 -0
  69. package/stream-shuffle.d.ts +3 -0
  70. package/stream-sort.d.ts +2 -0
  71. package/struct.d.ts +5 -3
  72. package/swizzle.d.ts +5 -3
  73. package/symmetric.d.ts +5 -3
  74. package/take-last.d.ts +2 -0
  75. package/take-nth.d.ts +2 -0
  76. package/take-while.d.ts +2 -0
  77. package/take.d.ts +2 -0
  78. package/toggle.d.ts +3 -1
  79. package/tween.d.ts +3 -0
  80. package/zip.d.ts +2 -0
package/CHANGELOG.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Change Log
2
2
 
3
- - **Last updated**: 2024-02-22T23:15:26Z
3
+ - **Last updated**: 2024-02-25T14:07:53Z
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.
package/api.d.ts CHANGED
@@ -39,6 +39,11 @@ export interface Reducer<A, B> extends Array<any> {
39
39
  *
40
40
  * @example
41
41
  * ```ts
42
+ * import {
43
+ * comp, drop, map, push, range, transduce
44
+ * type IXform
45
+ * } from "@thi.ng/transducers";
46
+ *
42
47
  * class Mul implements IXform<number, number> {
43
48
  * constructor(public factor = 10) {}
44
49
  *
package/auto-obj.d.ts CHANGED
@@ -6,6 +6,8 @@ import type { Reducer } from "./api.js";
6
6
  *
7
7
  * @example
8
8
  * ```ts
9
+ * import { autoObj } from "@thi.ng/transducers";
10
+ *
9
11
  * autoObj("id", ["foo", "bar", "baz"])
10
12
  * // { id0: "foo", id1: "bar", id2: "baz" }
11
13
  * ```
package/cat.d.ts CHANGED
@@ -12,12 +12,14 @@ import type { Transducer } from "./api.js";
12
12
  * behavior allows a {@link mapcat} user functions to benefit from reduced
13
13
  * results.
14
14
  *
15
- * Also see:
16
- * - {@link concat}
17
- * - {@link mapcat}
15
+ * Also see {@link concat}, {@link mapcat}.
18
16
  *
19
17
  * @example
20
18
  * ```ts
19
+ * import {
20
+ * cat, comp, iterator, map, mapcat, mapIndexed, reduced
21
+ * } from "@thi.ng/transducers";
22
+ *
21
23
  * [...iterator(comp(map((x) => [x, x]), cat()), [1, 2, 3, 4])]
22
24
  * // [ 1, 1, 2, 2, 3, 3, 4, 4 ]
23
25
  *
package/choices.d.ts CHANGED
@@ -4,14 +4,18 @@ import type { IRandom } from "@thi.ng/random";
4
4
  * If `weights` is given, it must have at least the same size as `choices`. If
5
5
  * omitted, each choice will have same probability.
6
6
  *
7
+ * @remarks
8
+ * Internally uses
9
+ * [`weightedRandom()`](https://docs.thi.ng/umbrella/random/functions/weightedRandom.html).
10
+ *
7
11
  * @example
8
12
  * ```ts
13
+ * import { choices, frequencies, take, transduce } from "@thi.ng/transducers";
14
+ *
9
15
  * transduce(take(1000), frequencies(), choices("abcd", [1, 0.5, 0.25, 0.125]))
10
16
  * // Map { 'c' => 132, 'a' => 545, 'b' => 251, 'd' => 72 }
11
17
  * ```
12
18
  *
13
- * [`weightedRandom()`](https://docs.thi.ng/umbrella/random/functions/weightedRandom.html)
14
- *
15
19
  * @param choices -
16
20
  * @param weights -
17
21
  */
package/compr.d.ts CHANGED
@@ -16,6 +16,8 @@ import type { Reducer, ReductionFn } from "./api.js";
16
16
  *
17
17
  * @example
18
18
  * ```ts
19
+ * import { compR } from "@thi.ng/transducers";
20
+ *
19
21
  * compR(rfn, fn)
20
22
  * // [rfn[0], rfn[1], fn]
21
23
  * ```
package/concat.d.ts CHANGED
@@ -6,6 +6,8 @@ import type { Nullable } from "@thi.ng/api";
6
6
  *
7
7
  * @example
8
8
  * ```ts
9
+ * import { concat } from "@thi.ng/transducers";
10
+ *
9
11
  * [...concat([1, 2, 3], null, [4, 5])]
10
12
  * // [ 1, 2, 3, 4, 5 ]
11
13
  *
package/consume.d.ts CHANGED
@@ -8,6 +8,8 @@
8
8
  *
9
9
  * @example
10
10
  * ```ts
11
+ * import { consume, repeatedly2d } from "@thi.ng/transducers";
12
+ *
11
13
  * consume(repeatedly2d((x, y) => console.log("output:", [x, y]), 2, 3));
12
14
  * // output: [ 0, 0 ]
13
15
  * // output: [ 1, 0 ]
package/converge.d.ts CHANGED
@@ -16,6 +16,8 @@ import type { Transducer } from "./api.js";
16
16
  *
17
17
  * @example
18
18
  * ```ts
19
+ * import { converge, iterate } from "@thi.ng/transducers";
20
+ *
19
21
  * // process as long as difference to prev value is >= 0.01
20
22
  * [...converge(
21
23
  * // predicate
package/curve.d.ts CHANGED
@@ -15,6 +15,8 @@
15
15
  *
16
16
  * @example
17
17
  * ```ts
18
+ * import { curve } from "@thi.ng/transducers";
19
+ *
18
20
  * [...curve(50, 100, 10, 2)]
19
21
  * // [
20
22
  * // 50,
package/cycle.d.ts CHANGED
@@ -8,6 +8,8 @@
8
8
  *
9
9
  * @example
10
10
  * ```ts
11
+ * import { cycle, range, take } from "@thi.ng/transducers";
12
+ *
11
13
  * // take 5 from infinite sequence
12
14
  * [...take(5, cycle([1, 2, 3]))]
13
15
  * // [1, 2, 3, 1, 2]
package/dedupe.d.ts CHANGED
@@ -9,6 +9,8 @@ import type { Transducer } from "./api.js";
9
9
  *
10
10
  * @example
11
11
  * ```ts
12
+ * import { dedupe } from "@thi.ng/transducers";
13
+ *
12
14
  * [...dedupe([1, 1, 2, 3, 3, 3, 1])]
13
15
  * // [ 1, 2, 3, 1 ]
14
16
  * ```
@@ -19,6 +19,8 @@ import type { TransformSpec } from "./api.js";
19
19
  *
20
20
  * @example
21
21
  * ```ts
22
+ * import { deepTransform } from "@thi.ng/transducers";
23
+ *
22
24
  * // source object to be transformed
23
25
  * src = {
24
26
  * meta: {
@@ -33,11 +35,11 @@ import type { TransformSpec } from "./api.js";
33
35
  * // deep transformation spec
34
36
  * spec = [
35
37
  * // root transform (called last)
36
- * ({type, meta, title, body}) => ["div", {class: type}, title, meta, body],
38
+ * ({ type, meta, title, body }) => ["div", { class: type }, title, meta, body],
37
39
  * // object of transform sub-specs
38
40
  * {
39
41
  * meta: [
40
- * ({author, date}) => ["div.meta", author, `(${date})`],
42
+ * ({ author, date }) => ["div.meta", author, `(${date})`],
41
43
  * {
42
44
  * author: ({email, name}) => ["a", {href: `mailto:${email}`}, name],
43
45
  * date: (d) => new Date(d).toLocaleString()
package/distinct.d.ts CHANGED
@@ -18,6 +18,8 @@ export interface DistinctOpts<T> {
18
18
  *
19
19
  * @example
20
20
  * ```ts
21
+ * import { distinct } from "@thi.ng/transducers";
22
+ *
21
23
  * [...distinct({ key: (x) => x.id }, [{id: 1, x: 2}, {id: 1, x: 3}])]
22
24
  * // [ { id: 1, x: 2 } ]
23
25
  * ```
package/dup.d.ts CHANGED
@@ -8,6 +8,8 @@
8
8
  *
9
9
  * @example
10
10
  * ```ts
11
+ * import { dup } from "@thi.ng/transducers";
12
+ *
11
13
  * dup("hello"); // "hellohello"
12
14
  * dup([1, 2, 3]); // [1, 2, 3, 1, 2, 3]
13
15
  * dup(range(3)); // IterableIterator<number>
package/every.d.ts CHANGED
@@ -10,7 +10,9 @@ import type { Reducer } from "./api.js";
10
10
  *
11
11
  * @example
12
12
  * ```ts
13
- * reduce(every((x)=> x > 0), [1,2,-1,3]);
13
+ * import { every } from "@thi.ng/transducers";
14
+ *
15
+ * every((x)=> x > 0, [1,2,-1,3]);
14
16
  * // false
15
17
  * ```
16
18
  *
package/extend-sides.d.ts CHANGED
@@ -9,6 +9,8 @@
9
9
  *
10
10
  * @example
11
11
  * ```ts
12
+ * import { extendSides } from "@thi.ng/transducers";
13
+ *
12
14
  * [...extendSides([1, 2, 3])]
13
15
  * // [ 1, 1, 2, 3, 3]
14
16
  *
package/filter-fuzzy.d.ts CHANGED
@@ -24,6 +24,8 @@ export interface FilterFuzzyOpts<A, B> {
24
24
  *
25
25
  * @example
26
26
  * ```ts
27
+ * import { filterFuzzy } from "@thi.ng/transducers";
28
+ *
27
29
  * [...filterFuzzy("ho", ["hello", "hallo", "hey", "heyoka"])]
28
30
  * // ["hello", "hallo", "heyoka"]
29
31
  * ```
package/flatten-with.d.ts CHANGED
@@ -14,6 +14,8 @@ export type MaybeIterable<T> = Nullable<Iterable<T>>;
14
14
  *
15
15
  * @example
16
16
  * ```ts
17
+ * import { flattenWith } from "@thi.ng/transducers";
18
+ *
17
19
  * // custom predicate which converts objects into key/val tuples,
18
20
  * // returns iterables as is and null for everything else
19
21
  * const pred = (x) =>
package/flatten.d.ts CHANGED
@@ -10,6 +10,8 @@ import type { Transducer } from "./api.js";
10
10
  *
11
11
  * @example
12
12
  * ```ts
13
+ * import { flatten } from "@thi.ng/transducers";
14
+ *
13
15
  * [...flatten([[1, [2, 3]], ["abc", "cde"]])]
14
16
  * // [1, 2, 3, "abc", "def"]
15
17
  *
package/group-binary.d.ts CHANGED
@@ -18,6 +18,8 @@ import type { Reducer } from "./api.js";
18
18
  *
19
19
  * @example
20
20
  * ```ts
21
+ * import { groupBinary, reduce } from "@thi.ng/transducers";
22
+ *
21
23
  * tree = reduce(
22
24
  * groupBinary(4, x => x.id & 0xf),
23
25
  * [{id: 3}, {id: 8}, {id: 15}, {id: 0}]
@@ -35,6 +37,8 @@ import type { Reducer } from "./api.js";
35
37
  *
36
38
  * @example
37
39
  * ```ts
40
+ * import { groupBinary, identity, push, reduce } from "@thi.ng/transducers";
41
+ *
38
42
  * tree = reduce(
39
43
  * groupBinary(4, identity, ()=>[], push(), 0, 1),
40
44
  * [1,2,3,4,5,6,7]
@@ -51,6 +55,8 @@ import type { Reducer } from "./api.js";
51
55
  *
52
56
  * @example
53
57
  * ```ts
58
+ * import { frequencies, groupBinary, reduce } from "@thi.ng/transducers";
59
+ *
54
60
  * tree = reduce(
55
61
  * groupBinary(3, (x: string) => x.length, null, frequencies()),
56
62
  * "aa bbb dddd ccccc bbb eeee fff".split(" ")
package/interpolate.d.ts CHANGED
@@ -22,6 +22,8 @@ import type { Transducer } from "./api.js";
22
22
  *
23
23
  * @example
24
24
  * ```ts
25
+ * import { interpolate } from "@thi.ng/transducers";
26
+ *
25
27
  * [...interpolate(
26
28
  * ([a, b], t) => a + (b - a) * t,
27
29
  * 2,
package/iterate.d.ts CHANGED
@@ -11,6 +11,8 @@ import type { Fn2 } from "@thi.ng/api";
11
11
  *
12
12
  * @example
13
13
  * ```ts
14
+ * import { iterate } from "@thi.ng/transducers";
15
+ *
14
16
  * [...iterate((x) => x * 2, 1, 5)]
15
17
  * // [ 1, 2, 4, 8, 16 ]
16
18
  *
package/juxtr.d.ts CHANGED
@@ -12,6 +12,8 @@ import type { Reducer } from "./api.js";
12
12
  *
13
13
  * @example
14
14
  * ```ts
15
+ * import { add, juxtR, reduce, reductions, str } from "@thi.ng/transducers";
16
+ *
15
17
  * reduce(juxtR(add(), reductions(add()), str("-")), [1, 2, 3, 4]);
16
18
  * // [ 10, [ 0, 1, 3, 6, 10 ], '1-2-3-4' ]
17
19
  * ```
@@ -13,6 +13,8 @@ import type { IObjectOf } from "@thi.ng/api";
13
13
  *
14
14
  * @example
15
15
  * ```ts
16
+ * import { keyPermutations } from "@thi.ng/transducers";
17
+ *
16
18
  * [...keyPermutations({ a: [1, 2], b: [true, false], c: ["X", "Y"] })]
17
19
  * // [
18
20
  * // { a: 1, b: true, c: 'X' },
package/length.d.ts CHANGED
@@ -7,6 +7,8 @@ import type { ILength } from "@thi.ng/api";
7
7
  *
8
8
  * @example
9
9
  * ```ts
10
+ * import { length } from "@thi.ng/transducers";
11
+ *
10
12
  * [...length(0, ["a", "bc", "def"])]
11
13
  * // [1, 2, 3]
12
14
  * ```
package/line.d.ts CHANGED
@@ -12,6 +12,8 @@
12
12
  *
13
13
  * @example
14
14
  * ```ts
15
+ * import { line } from "@thi.ng/transducers";
16
+ *
15
17
  * [...line(50, 100, 10)]
16
18
  * // [
17
19
  * // 50, 55, 60, 65, 70,
package/lookup.d.ts CHANGED
@@ -4,6 +4,8 @@
4
4
  *
5
5
  * @example
6
6
  * ```ts
7
+ * import { lookup1d, map } from "@thi.ng/transducers";
8
+ *
7
9
  * [...map(lookup1d([10, 20, 30]), [2,0,1])]
8
10
  * // [ 30, 10, 20 ]
9
11
  * ```
@@ -22,6 +24,8 @@ export declare const lookup1d: <T>(src: T[]) => (i: number) => T;
22
24
  *
23
25
  * @example
24
26
  * ```ts
27
+ * import { lookup2d, map, range, range2d } from "@thi.ng/transducers";
28
+ *
25
29
  * [...map(lookup2d([...range(9)], 3), range2d(2, -1, 0, 3))]
26
30
  * // [ 2, 1, 0, 5, 4, 3, 8, 7, 6 ]
27
31
  * ```
package/map-indexed.d.ts CHANGED
@@ -9,6 +9,8 @@ import type { Transducer } from "./api.js";
9
9
  *
10
10
  * @example
11
11
  * ```ts
12
+ * import { assocObj, mapIndexed, transduce } from "@thi.ng/transducers";
13
+ *
12
14
  * transduce(
13
15
  * mapIndexed((i, x) => ["id" + i, x * 10], 42),
14
16
  * assocObj(),
package/map-keys.d.ts CHANGED
@@ -9,6 +9,8 @@ import type { Transducer } from "./api.js";
9
9
  *
10
10
  * @example
11
11
  * ```ts
12
+ * import { mapKeys } from "@thi.ng/transducers";
13
+ *
12
14
  * [...mapKeys(
13
15
  * {
14
16
  * a: (x) => x != null ? x * 10 : x,
package/map-nth.d.ts CHANGED
@@ -10,6 +10,8 @@ import type { Transducer } from "./api.js";
10
10
  *
11
11
  * @example
12
12
  * ```ts
13
+ * import { mapNth } from "@thi.ng/transducers";
14
+ *
13
15
  * [...mapNth(3, (x) => x * 10, range(1,10))]
14
16
  * // [ 10, 2, 3, 40, 5, 6, 70, 8, 9 ]
15
17
  *
package/map-vals.d.ts CHANGED
@@ -11,6 +11,8 @@ import type { Transducer } from "./api.js";
11
11
  *
12
12
  * @example
13
13
  * ```ts
14
+ * import { mapVals } from "@thi.ng/transducers";
15
+ *
14
16
  * [...mapVals((x)=> x * 10, [{a: 1, b: 2}, {c: 3, d: 4}])]
15
17
  * // [ { a: 10, b: 20 }, { c: 30, d: 40 } ]
16
18
  * ```
package/map.d.ts CHANGED
@@ -6,6 +6,8 @@ import type { Transducer } from "./api.js";
6
6
  *
7
7
  * @example
8
8
  * ```ts
9
+ * import { map } from "@thi.ng/transducers";
10
+ *
9
11
  * [...map((x) => x * 10, [1, 2, 3])]
10
12
  * // [ 10, 20, 30 ]
11
13
  * ```
package/match-first.d.ts CHANGED
@@ -5,7 +5,10 @@ import type { Transducer } from "./api.js";
5
5
  *
6
6
  * @example
7
7
  * ```ts
8
+ * import { comp, filter, take } from "@thi.ng/transducers";
9
+ *
8
10
  * comp(filter(pred), take(1))
11
+ * // [Function]
9
12
  * ```
10
13
  *
11
14
  * Yields none or only the first value which passed the predicate check
@@ -14,6 +17,8 @@ import type { Transducer } from "./api.js";
14
17
  *
15
18
  * @example
16
19
  * ```ts
20
+ * import { comp, map, matchFirst, push, transduce } from "@thi.ng/transducers";
21
+ *
17
22
  * matchFirst((x) => x >= 5, [3, 1, 4, 2, 6, 5])
18
23
  * // 6
19
24
  *
@@ -22,10 +27,10 @@ import type { Transducer } from "./api.js";
22
27
  * matchFirst((x) => x >= 5),
23
28
  * map((x) => x * 10)
24
29
  * ),
25
- * last(),
30
+ * push(),
26
31
  * [3, 1, 4, 2, 6, 5]
27
32
  * )
28
- * // 60
33
+ * // [60]
29
34
  * ```
30
35
  *
31
36
  * @param pred - predicate function
package/match-last.d.ts CHANGED
@@ -1,18 +1,14 @@
1
1
  import type { Predicate } from "@thi.ng/api";
2
2
  import type { Transducer } from "./api.js";
3
3
  /**
4
- * Transducer composition / syntax sugar for:
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`).
5
7
  *
6
8
  * @example
7
9
  * ```ts
8
- * comp(filter(pred), takeLast(1))
9
- * ```
10
- *
11
- * Yields none or only the last value which passed the predicate check.
12
- * If `src` input is given, returns last match found (or `undefined`).
10
+ * import { comp, map, matchLast, push, transduce } from "@thi.ng/transducers";
13
11
  *
14
- * @example
15
- * ```ts
16
12
  * matchLast((x) => x >= 5, [3, 1, 6, 5, 4, 2])
17
13
  * // 5
18
14
  *
@@ -21,8 +17,8 @@ import type { Transducer } from "./api.js";
21
17
  * matchLast((x) => x >= 5),
22
18
  * map((x) => x * 10)
23
19
  * ),
24
- * last(),
25
- * [3, 1, 4, 2, 6, 5]
20
+ * push(),
21
+ * [3, 1, 6, 5, 4, 2]
26
22
  * )
27
23
  * // 50
28
24
  * ```
@@ -6,6 +6,8 @@ import type { MultiplexTxLike, Reducer, Transducer } from "./api.js";
6
6
  *
7
7
  * @example
8
8
  * ```ts
9
+ * import { multiplexObj } from "@thi.ng/transducers";
10
+ *
9
11
  * [...multiplexObj(
10
12
  * {
11
13
  * initial: map(x => x.charAt(0)),
package/multiplex.d.ts CHANGED
@@ -22,6 +22,8 @@ import type { MultiplexTxLike, Transducer } from "./api.js";
22
22
  *
23
23
  * @example
24
24
  * ```ts
25
+ * import { iterator, map, multiplex } from "@thi.ng/transducers";
26
+ *
25
27
  * [...iterator(
26
28
  * multiplex(
27
29
  * map(x => x.charAt(0)),
@@ -36,6 +38,8 @@ import type { MultiplexTxLike, Transducer } from "./api.js";
36
38
  *
37
39
  * @example
38
40
  * ```ts
41
+ * import { iterator, map, mapcat, multiplex } from "@thi.ng/transducers";
42
+ *
39
43
  * [...iterator(
40
44
  * multiplex(
41
45
  * // override default unwrap behavior for this transducer
package/norm-count.d.ts CHANGED
@@ -10,6 +10,8 @@ import type { Reducer } from "./api.js";
10
10
  *
11
11
  * @example
12
12
  * ```ts
13
+ * import { filter, normCount, transduce } from "@thi.ng/transducers";
14
+ *
13
15
  * const items = [1,2,3,1,1,4,2,5,1,2];
14
16
  *
15
17
  * // compute percentage of values < 3
@@ -6,6 +6,8 @@ import type { Reducer } from "./api.js";
6
6
  *
7
7
  * @example
8
8
  * ```ts
9
+ * import { normFrequenciesAuto } from "@thi.ng/transducers";
10
+ *
9
11
  * const items = [1, 2, 3, 1, 1, 4, 2, 5, 1, 2];
10
12
  *
11
13
  * normFrequenciesAuto(items)
@@ -4,8 +4,13 @@ import type { Reducer } from "./api.js";
4
4
  * Similar to {@link frequencies}, but with each bin value normalized to given
5
5
  * `norm`.
6
6
  *
7
+ * @remarks
8
+ * Also see {@link normFrequenciesAuto}.
9
+ *
7
10
  * @example
8
11
  * ```ts
12
+ * import { normFrequencies } from "@thi.ng/transducers";
13
+ *
9
14
  * const items = [1, 2, 3, 1, 1, 4, 2, 5, 1, 2];
10
15
  *
11
16
  * normFrequencies(10, items)
package/norm-range.d.ts CHANGED
@@ -5,6 +5,8 @@
5
5
  *
6
6
  * @example
7
7
  * ```ts
8
+ * import { normRange } from "@thi.ng/transducers";
9
+ *
8
10
  * [...normRange(4)]
9
11
  * // [0, 0.25, 0.5, 0.75, 1.0]
10
12
  *
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@thi.ng/transducers",
3
- "version": "8.9.6",
3
+ "version": "8.9.7",
4
4
  "description": "Lightweight transducer implementations for ES6 / TypeScript",
5
5
  "type": "module",
6
6
  "module": "./index.js",
@@ -39,14 +39,14 @@
39
39
  "test": "bun test"
40
40
  },
41
41
  "dependencies": {
42
- "@thi.ng/api": "^8.9.25",
43
- "@thi.ng/arrays": "^2.8.2",
42
+ "@thi.ng/api": "^8.9.26",
43
+ "@thi.ng/arrays": "^2.8.3",
44
44
  "@thi.ng/checks": "^3.5.0",
45
- "@thi.ng/compare": "^2.2.21",
46
- "@thi.ng/compose": "^2.1.64",
45
+ "@thi.ng/compare": "^2.2.22",
46
+ "@thi.ng/compose": "^2.1.65",
47
47
  "@thi.ng/errors": "^2.4.18",
48
- "@thi.ng/math": "^5.10.2",
49
- "@thi.ng/random": "^3.6.32"
48
+ "@thi.ng/math": "^5.10.3",
49
+ "@thi.ng/random": "^3.6.33"
50
50
  },
51
51
  "devDependencies": {
52
52
  "@microsoft/api-extractor": "^7.40.1",
@@ -588,5 +588,5 @@
588
588
  ],
589
589
  "year": 2016
590
590
  },
591
- "gitHead": "16f2b92b5410bd35dcde6c2971c8e62783ebc472\n"
591
+ "gitHead": "6e20f80dd9df1c8055ffa3c1e4d6f7598add0c0b\n"
592
592
  }
package/pad-last.d.ts CHANGED
@@ -12,6 +12,8 @@ import type { Transducer } from "./api.js";
12
12
  *
13
13
  * @example
14
14
  * ```ts
15
+ * import { padLast } from "@thi.ng/transducers";
16
+ *
15
17
  * [...padLast(8, 0, [1, 2, 3, 4, 5])]
16
18
  * // [ 1, 2, 3, 4, 5, 0, 0, 0 ]
17
19
  *
package/pad-sides.d.ts CHANGED
@@ -1,13 +1,17 @@
1
1
  /**
2
2
  * Returns iterator of `src` padded with value `x`, repeated
3
- * `numLeft`/`numRight` times (default: 1). By default both sides are
4
- * padded, but can be adjusted by setting either of them to zero.
5
- * `numRight` defaults to same value as `numLeft`.
3
+ * `numLeft`/`numRight` times (default: 1). By default both sides are padded,
4
+ * but can be adjusted by setting either of them to zero. `numRight` defaults to
5
+ * same value as `numLeft`.
6
6
  *
7
- * @example
8
- * Essentially, syntax sugar for:
7
+ * @remarks
8
+ * Essentially syntax sugar for code below. Also see {@link extendSides},
9
+ * {@link wrapSides}.
9
10
  *
11
+ * @example
10
12
  * ```ts
13
+ * import { concat, repeat } from "@thi.ng/transducers";
14
+ *
11
15
  * // default
12
16
  * concat(repeat(x, numLeft), src, repeat(x, numRight))
13
17
  *
@@ -18,9 +22,6 @@
18
22
  * concat(src, repeat(x, numRight))
19
23
  * ```
20
24
  *
21
- * - {@link extendSides}
22
- * - {@link wrapSides}
23
- *
24
25
  * @param src -
25
26
  * @param x -
26
27
  * @param numLeft -
package/page.d.ts CHANGED
@@ -9,6 +9,8 @@ import type { Transducer } from "./api.js";
9
9
  *
10
10
  * @example
11
11
  * ```ts
12
+ * import { page, range } from "@thi.ng/transducers";
13
+ *
12
14
  * [...page(0, 5, range(12))]
13
15
  * // [ 0, 1, 2, 3, 4 ]
14
16
  *
package/pairs.d.ts CHANGED
@@ -9,6 +9,8 @@ import type { IObjectOf } from "@thi.ng/api";
9
9
  *
10
10
  * @example
11
11
  * ```ts
12
+ * import { pairs } from "@thi.ng/transducers";
13
+ *
12
14
  * [...pairs({ a: 1, b: 2 })]
13
15
  * // [['a', 1], ['b', 2]]
14
16
  * ```
package/palindrome.d.ts CHANGED
@@ -8,6 +8,8 @@
8
8
  *
9
9
  * @example
10
10
  * ```ts
11
+ * import { palindrome } from "@thi.ng/transducers";
12
+ *
11
13
  * palindrome("hello"); // "helloolleh"
12
14
  * palindrome([1, 2, 3]); // [1, 2, 3, 3, 2, 1]
13
15
  * palindrome(range(3)); // IterableIterator<number>
package/partition-by.d.ts CHANGED
@@ -7,6 +7,8 @@ import type { Transducer } from "./api.js";
7
7
  *
8
8
  * @example
9
9
  * ```ts
10
+ * import { partitionBy } from "@thi.ng/transducers";
11
+ *
10
12
  * [...partitionBy((x) => x & 1, [1, 2, 4, 6, 3, 5, 8, 4])]
11
13
  * // [ [ 1 ], [ 2, 4, 6 ], [ 3, 5 ], [ 8, 4 ] ]
12
14
  * ```
package/partition-of.d.ts CHANGED
@@ -5,6 +5,8 @@ import type { Transducer } from "./api.js";
5
5
  *
6
6
  * @example
7
7
  * ```ts
8
+ * import { partitionOf } from "@thi.ng/transducers";
9
+ *
8
10
  * [...partitionOf([3,2,4], range(20))]
9
11
  * // [ [ 0, 1, 2 ],
10
12
  * // [ 3, 4 ],
@@ -11,6 +11,8 @@ import type { SortOpts, Transducer } from "./api.js";
11
11
  *
12
12
  * @example
13
13
  * ```ts
14
+ * import { partitionSort } from "@thi.ng/transducers";
15
+ *
14
16
  * [...partitionSort(4, [5,9,2,6,4,1,3,8,7,0])]
15
17
  * // [ 2, 5, 6, 9, 1, 3, 4, 8, 0, 7 ]
16
18
  *
@@ -69,6 +69,8 @@ export interface PartitionSyncOpts<T> {
69
69
  *
70
70
  * @example
71
71
  * ```ts
72
+ * import { partitionSync } from "@thi.ng/transducers";
73
+ *
72
74
  * src = [
73
75
  * ["a", 1], ["a", 2], ["d", 100], ["b", 10],
74
76
  * ["b", 11], ["c", 0], ["a", 3]
@@ -88,7 +90,10 @@ export interface PartitionSyncOpts<T> {
88
90
  * available (with other values in the tuple remaining). Compare with
89
91
  * above example:
90
92
  *
93
+ * @example
91
94
  * ```ts
95
+ * import { partitionSync } from "@thi.ng/transducers";
96
+ *
92
97
  * // passing `false` to disable tuple reset
93
98
  * [...partitionSync(
94
99
  * ["a", "b"],
@@ -7,6 +7,8 @@ import type { Transducer } from "./api.js";
7
7
  *
8
8
  * @example
9
9
  * ```ts
10
+ * import { partitionWhen } from "@thi.ng/transducers";
11
+ *
10
12
  * [...partitionWhen((x) => !!x, [0, 1, 0, 0, 1, 1, 0, 1])]
11
13
  * // [ [ 0 ], [ 1, 0, 0 ], [ 1 ], [ 1, 0 ], [ 1 ] ]
12
14
  * ```
package/partition.d.ts CHANGED
@@ -8,6 +8,8 @@ import type { Transducer } from "./api.js";
8
8
  *
9
9
  * @example
10
10
  * ```ts
11
+ * import { partition } from "@thi.ng/transducers";
12
+ *
11
13
  * [...partition(3, range(10))]
12
14
  * // [ [ 0, 1, 2 ], [ 3, 4, 5 ], [ 6, 7, 8 ] ]
13
15
  *
package/peek.d.ts CHANGED
@@ -6,6 +6,8 @@ import type { Transducer } from "./api.js";
6
6
  *
7
7
  * @example
8
8
  * ```ts
9
+ * import { peek } from "@thi.ng/transducers";
10
+ *
9
11
  * [...peek([ [1, 2, 3], [4, 5] ])]
10
12
  * // [ 3, 5 ]
11
13
  * ```
package/permutations.d.ts CHANGED
@@ -7,6 +7,8 @@
7
7
  *
8
8
  * @example
9
9
  * ```ts
10
+ * import { permutations } from "@thi.ng/transducers";
11
+ *
10
12
  * [...permutations("ab", range(3))]
11
13
  * // [ ['a', 0], ['a', 1], ['a', 2],
12
14
  * // ['b', 0], ['b', 1], ['b', 2] ]
@@ -36,6 +38,8 @@ export declare function permutations(...src: Iterable<any>[]): IterableIterator<
36
38
  *
37
39
  * @example
38
40
  * ```ts
41
+ * import { permutationsN } from "@thi.ng/transducers";
42
+ *
39
43
  * [...permutationsN(2)]
40
44
  * // [ [0, 0], [0, 1], [1, 0], [1, 1] ]
41
45
  *
package/pluck.d.ts CHANGED
@@ -5,6 +5,8 @@ import type { Transducer } from "./api.js";
5
5
  *
6
6
  * @example
7
7
  * ```ts
8
+ * import { pluck } from "@thi.ng/transducers";
9
+ *
8
10
  * [...pluck("id", [{id: 1}, {id: 2}, {}])]
9
11
  * // [ 1, 2, undefined ]
10
12
  * ```
package/range-nd.d.ts CHANGED
@@ -8,6 +8,8 @@ import type { ArrayLikeIterable } from "@thi.ng/api";
8
8
  *
9
9
  * @example
10
10
  * ```ts
11
+ * import { rangeNd } from "@thi.ng/transducers";
12
+ *
11
13
  * [...rangeNd([2])]
12
14
  * // [ [ 0 ], [ 1 ] ]
13
15
  *
package/rechunk.d.ts CHANGED
@@ -12,6 +12,8 @@ import type { Transducer } from "./api.js";
12
12
  *
13
13
  * @example
14
14
  * ```ts
15
+ * import { rechunk } from "@thi.ng/transducers";
16
+ *
15
17
  * [...rechunk(/-/, ["abc-d", "ef-g-", "hij", "-k-lm"])]
16
18
  * // [ "abc", "def", "g", "hij", "k", "lm" ]
17
19
  * ```
package/repeat.d.ts CHANGED
@@ -6,6 +6,8 @@
6
6
  *
7
7
  * @example
8
8
  * ```ts
9
+ * import { repeat } from "@thi.ng/transducers";
10
+ *
9
11
  * [...repeat(42, 5)]
10
12
  * // [42, 42, 42, 42, 42]
11
13
  * ```
package/repeatedly.d.ts CHANGED
@@ -6,6 +6,8 @@ import type { Fn } from "@thi.ng/api";
6
6
  *
7
7
  * @example
8
8
  * ```ts
9
+ * import { repeatedly } from "@thi.ng/transducers";
10
+ *
9
11
  * [...repeatedly(() => Math.floor(Math.random() * 10), 5)]
10
12
  * // [7, 0, 9, 3, 1]
11
13
  *
package/repeatedly2d.d.ts CHANGED
@@ -6,6 +6,8 @@ import type { FnU2 } from "@thi.ng/api";
6
6
  *
7
7
  * @example
8
8
  * ```ts
9
+ * import { repeatedly2d } from "@thi.ng/transducers";
10
+ *
9
11
  * [...repeatedly2d((x, y) => [(x + 1) * 10, (y + 1) * 100], 2, 3)]
10
12
  * // [
11
13
  * // [ 10, 100 ], [ 20, 100 ],
package/repeatedly3d.d.ts CHANGED
@@ -6,6 +6,8 @@ import type { FnU3 } from "@thi.ng/api";
6
6
  *
7
7
  * @example
8
8
  * ```ts
9
+ * import { repeatedly3d } from "@thi.ng/transducers";
10
+ *
9
11
  * [...repeatedly3d((x, y, z) => [(x+1)*10, (y+1)*100, (z+1)*1000], 2, 2, 2)]
10
12
  * // [
11
13
  * // [ 10, 100, 1000 ], [ 20, 100, 1000 ], [ 10, 200, 1000 ], [ 20, 200, 1000 ],
package/reverse.d.ts CHANGED
@@ -4,7 +4,9 @@
4
4
  *
5
5
  * @example
6
6
  * ```ts
7
- * [...tx.reverse("hello world")]
7
+ * import { reverse } from "@thi.ng/transducers";
8
+ *
9
+ * [...reverse("hello world")]
8
10
  * // [ "d", "l", "r", "o", "w", " ", "o", "l", "l", "e", "h" ]
9
11
  * ```
10
12
  *
package/sample.d.ts CHANGED
@@ -7,6 +7,8 @@ import type { Transducer } from "./api.js";
7
7
  *
8
8
  * @example
9
9
  * ```ts
10
+ * import { range, sample } from "@thi.ng/transducers";
11
+ *
10
12
  * // 10% probability
11
13
  * [...sample(0.1, range(100))]
12
14
  * // [ 3, 24, 25, 36, 43, 49, 59, 64, 82, 86, 89 ]
package/scan.d.ts CHANGED
@@ -12,6 +12,10 @@ import type { Reducer, Transducer } from "./api.js";
12
12
  *
13
13
  * @example
14
14
  * ```ts
15
+ * import {
16
+ * add, comp, last, length, multiplex, range, scan, transduce
17
+ * } from "@thi.ng/transducers";
18
+ *
15
19
  * [...iterator(scan(add()), range(10))]
16
20
  * // [ 0, 1, 3, 6, 10, 15, 21, 28, 36, 45 ]
17
21
  *
package/select-keys.d.ts CHANGED
@@ -9,6 +9,8 @@ import type { Transducer } from "./api.js";
9
9
  *
10
10
  * @example
11
11
  * ```ts
12
+ * import { selectKeys } from "@thi.ng/transducers";
13
+ *
12
14
  * [...selectKeys(
13
15
  * ["id", "age"],
14
16
  * [
@@ -13,6 +13,8 @@ import type { Transducer } from "./api.js";
13
13
  *
14
14
  * @example
15
15
  * ```ts
16
+ * import { range, slidingWindow } from "@thi.ng/transducers";
17
+ *
16
18
  * [...slidingWindow(3, range(5))]
17
19
  * // [ [ 0 ], [ 0, 1 ], [ 0, 1, 2 ], [ 1, 2, 3 ], [ 2, 3, 4 ] ]
18
20
  *
package/step.d.ts CHANGED
@@ -12,6 +12,8 @@ import type { TxLike } from "./api.js";
12
12
  *
13
13
  * @example
14
14
  * ```ts
15
+ * import { filter, map, macat, step, take } from "@thi.ng/transducers";
16
+ *
15
17
  * // single result (unwrapped, default)
16
18
  * step(map(x => x * 10))(1);
17
19
  * // 10
@@ -27,6 +27,9 @@ export interface StreamShuffleOpts {
27
27
  *
28
28
  * @example
29
29
  * ```ts
30
+ * import { range, streamShuffle } from "@thi.ng/transducers";
31
+ * import { XsAdd } from "@thi.ng/random";
32
+ *
30
33
  * [...streamShuffle(5, range(10))]
31
34
  * // [ 3, 2, 5, 0, 8, 7, 1, 6, 4, 9 ]
32
35
  *
package/stream-sort.d.ts CHANGED
@@ -6,6 +6,8 @@ import type { SortOpts, Transducer } from "./api.js";
6
6
  *
7
7
  * @example
8
8
  * ```ts
9
+ * import { streamSort } from "@thi.ng/transducers";
10
+ *
9
11
  * [...streamSort(4, [5,9,2,6,4,1,3,8,7,0])]
10
12
  * // [ 2, 4, 1, 3, 5, 6, 0, 7, 8, 9 ]
11
13
  * ```
package/struct.d.ts CHANGED
@@ -20,9 +20,11 @@ export interface StructField extends Array<any> {
20
20
  *
21
21
  * @example
22
22
  * ```ts
23
- * tx.transduce(
24
- * tx.struct([["id", 1, (id) => id[0]], ["pos", 2], ["vel", 2], ["color", 4]]),
25
- * tx.push(),
23
+ * import { push, struct, transduce } from "@thi.ng/transducers";
24
+ *
25
+ * transduce(
26
+ * struct([["id", 1, (id) => id[0]], ["pos", 2], ["vel", 2], ["color", 4]]),
27
+ * push(),
26
28
  * [0, 100, 200, -1, 0, 1, 0.5, 0, 1, 1, 0, 0, 5, 4, 0, 0, 1, 1]
27
29
  * )
28
30
  * // [ { color: [ 1, 0.5, 0, 1 ],
package/swizzle.d.ts CHANGED
@@ -5,13 +5,15 @@ import type { Transducer } from "./api.js";
5
5
  *
6
6
  * @example
7
7
  * ```ts
8
- * [...swizzle([3,0,2,1], [[1,2,3,4], [10,20,30,40]])]
8
+ * import { swizzle } from "@thi.ng/transducers";
9
+ *
10
+ * [...swizzle([3, 0, 2, 1], [[1, 2, 3, 4], [10, 20, 30, 40]])]
9
11
  * // [ [ 4, 1, 3, 2 ], [ 40, 10, 30, 20 ] ]
10
12
  *
11
- * [...swizzle([0,0,1,1], [[1,2,3,4], [10,20,30,40]])]
13
+ * [...swizzle([0, 0, 1, 1], [[1, 2, 3, 4], [10, 20, 30, 40]])]
12
14
  * // [ [ 1, 1, 2, 2 ], [ 10, 10, 20, 20 ] ]
13
15
  *
14
- * [...swizzle(["z","x"], [{x: 1, y: 2, z: 3}])]
16
+ * [...swizzle(["z", "x"], [{x: 1, y: 2, z: 3}])]
15
17
  * // [ [ 3, 1 ] ]
16
18
  * ```
17
19
  *
package/symmetric.d.ts CHANGED
@@ -1,10 +1,12 @@
1
1
  /**
2
- * Yields an iterator of all `src` values, followed by the same values
3
- * in reverse order. Efficiently builds the reversed order via an
4
- * internal linked list.
2
+ * Yields an iterator of all `src` values, followed by the same values in
3
+ * reverse order. Efficiently builds the reversed order via an internal linked
4
+ * list.
5
5
  *
6
6
  * @example
7
7
  * ```ts
8
+ * import { symmetric } from "@thi.ng/transducers";
9
+ *
8
10
  * [...symmetric([1, 2, 3])]
9
11
  * // [ 1, 2, 3, 3, 2, 1 ]
10
12
  * ```
package/take-last.d.ts CHANGED
@@ -5,6 +5,8 @@ import type { Transducer } from "./api.js";
5
5
  *
6
6
  * @example
7
7
  * ```ts
8
+ * import { range, takeLast } from "@thi.ng/transducers";
9
+ *
8
10
  * [...takeLast(3, range(10))]
9
11
  * // [ 7, 8, 9 ]
10
12
  * ```
package/take-nth.d.ts CHANGED
@@ -5,6 +5,8 @@ import type { Transducer } from "./api.js";
5
5
  *
6
6
  * @example
7
7
  * ```ts
8
+ * import { range, takeNth } from "@thi.ng/transducers";
9
+ *
8
10
  * [...takeNth(3, range(10))]
9
11
  * // [ 0, 3, 6, 9 ]
10
12
  * ```
package/take-while.d.ts CHANGED
@@ -8,6 +8,8 @@ import type { Transducer } from "./api.js";
8
8
  *
9
9
  * @example
10
10
  * ```ts
11
+ * import { range, takeWhile } from "@thi.ng/transducers";
12
+ *
11
13
  * [...takeWhile((x) => x < 5, range(10))]
12
14
  * // [ 0, 1, 2, 3, 4 ]
13
15
  * ```
package/take.d.ts CHANGED
@@ -5,6 +5,8 @@ import type { Transducer } from "./api.js";
5
5
  *
6
6
  * @example
7
7
  * ```ts
8
+ * import { comp, map, range, take } from "@thi.ng/transducers";
9
+ *
8
10
  * [...iterator(comp(take(5), map((x) => x * 10)), range(10))]
9
11
  * // [ 0, 10, 20, 30, 40 ]
10
12
  * ```
package/toggle.d.ts CHANGED
@@ -7,10 +7,12 @@ import type { Transducer } from "./api.js";
7
7
  *
8
8
  * @example
9
9
  * ```ts
10
+ * import { toggle } from "@thi.ng/transducers";
11
+ *
10
12
  * [...toggle(1, 0, false, [1, 2, 3, 4])]
11
13
  * // [ 1, 0, 1, 0 ]
12
14
  *
13
- * [...tx.toggle("on", "off", true, [1, 2, 3, 4])]
15
+ * [...toggle("on", "off", true, [1, 2, 3, 4])]
14
16
  * // [ 'off', 'on', 'off', 'on' ]
15
17
  * ```
16
18
  *
package/tween.d.ts CHANGED
@@ -60,6 +60,8 @@ export interface TweenOpts<A, B, C> {
60
60
  *
61
61
  * @example
62
62
  * ```ts
63
+ * import { tween } from "@thi.ng/transducers";
64
+ *
63
65
  * [...tween({
64
66
  * num: 10,
65
67
  * min: 0,
@@ -76,6 +78,7 @@ export interface TweenOpts<A, B, C> {
76
78
  *
77
79
  * @example
78
80
  * ```ts
81
+ * import { tween } from "@thi.ng/transducers";
79
82
  * import { mix, smoothStep } from "@thi.ng/math"
80
83
  *
81
84
  * [...tween({
package/zip.d.ts CHANGED
@@ -14,6 +14,8 @@
14
14
  *
15
15
  * @example
16
16
  * ```ts
17
+ * import { zip } from "@thi.ng/transducers";
18
+ *
17
19
  * zip([1, 2, 3], [3, 4, 5, 0, 9])
18
20
  * // [ 1, 3 ] [ 2, 4 ] [ 3, 5 ]
19
21
  *