@thi.ng/transducers 8.8.13 → 8.8.15

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 (158) hide show
  1. package/CHANGELOG.md +1 -1
  2. package/add.js +5 -2
  3. package/api.js +0 -1
  4. package/as-iterable.js +5 -8
  5. package/assoc-map.js +8 -4
  6. package/assoc-obj.js +8 -4
  7. package/auto-obj.js +9 -5
  8. package/benchmark.js +14 -13
  9. package/cat.js +15 -49
  10. package/choices.js +6 -19
  11. package/comp.js +6 -3
  12. package/compr.js +4 -25
  13. package/concat.js +7 -20
  14. package/conj.js +8 -4
  15. package/consume.js +6 -24
  16. package/converge.js +18 -16
  17. package/convolve.js +66 -54
  18. package/count.js +14 -8
  19. package/curve.js +12 -45
  20. package/cycle.js +15 -34
  21. package/dedupe.js +21 -21
  22. package/deep-transform.js +17 -73
  23. package/delayed.js +4 -10
  24. package/distinct.js +17 -16
  25. package/div.js +8 -4
  26. package/drop-nth.js +12 -9
  27. package/drop-while.js +13 -8
  28. package/drop.js +12 -8
  29. package/dup.js +5 -6
  30. package/duplicate.js +13 -12
  31. package/ensure.js +4 -1
  32. package/every.js +13 -9
  33. package/extend-sides.js +15 -40
  34. package/fill.js +16 -9
  35. package/filter-fuzzy.js +13 -8
  36. package/filter.js +8 -7
  37. package/flatten-with.js +21 -20
  38. package/flatten.js +8 -2
  39. package/flatten1.js +5 -2
  40. package/frequencies.js +5 -3
  41. package/group-binary.js +15 -84
  42. package/group-by-map.js +25 -21
  43. package/group-by-obj.js +23 -22
  44. package/index.js +0 -4
  45. package/indexed.js +10 -7
  46. package/interleave.js +12 -11
  47. package/internal/drain.js +8 -15
  48. package/internal/group-opts.js +7 -11
  49. package/internal/mathop.js +10 -17
  50. package/internal/sort-opts.js +7 -11
  51. package/interpolate-hermite.js +10 -2
  52. package/interpolate-linear.js +10 -2
  53. package/interpolate.js +8 -4
  54. package/interpose.js +17 -16
  55. package/iterate.js +8 -28
  56. package/iterator.js +36 -62
  57. package/juxtr.js +74 -71
  58. package/keep.js +12 -7
  59. package/key-permutations.js +7 -30
  60. package/key-selector.js +4 -1
  61. package/keys.js +8 -16
  62. package/labeled.js +5 -4
  63. package/last.js +5 -2
  64. package/length.js +7 -6
  65. package/line.js +6 -29
  66. package/lookup.js +10 -44
  67. package/map-deep.js +5 -4
  68. package/map-indexed.js +10 -8
  69. package/map-keys.js +16 -13
  70. package/map-nth.js +34 -33
  71. package/map-vals.js +16 -13
  72. package/map.js +11 -13
  73. package/mapcat-indexed.js +5 -3
  74. package/mapcat.js +5 -2
  75. package/match-first.js +5 -4
  76. package/match-last.js +5 -4
  77. package/max-compare.js +11 -8
  78. package/max-mag.js +8 -4
  79. package/max.js +8 -4
  80. package/mean.js +10 -9
  81. package/min-compare.js +11 -8
  82. package/min-mag.js +8 -4
  83. package/min-max.js +4 -5
  84. package/min.js +8 -4
  85. package/moving-average.js +17 -16
  86. package/moving-median.js +17 -9
  87. package/mul.js +5 -2
  88. package/multiplex-obj.js +14 -8
  89. package/multiplex.js +12 -2
  90. package/noop.js +4 -6
  91. package/norm-count.js +10 -7
  92. package/norm-frequencies-auto.js +21 -18
  93. package/norm-frequencies.js +8 -6
  94. package/norm-range.js +20 -45
  95. package/package.json +14 -12
  96. package/pad-last.js +20 -19
  97. package/pad-sides.js +4 -35
  98. package/page.js +5 -3
  99. package/pairs.js +8 -22
  100. package/palindrome.js +5 -6
  101. package/partition-by.js +34 -34
  102. package/partition-of.js +14 -13
  103. package/partition-sort.js +15 -7
  104. package/partition-sync.js +118 -119
  105. package/partition-time.js +12 -11
  106. package/partition-when.js +28 -27
  107. package/partition.js +45 -44
  108. package/peek.js +5 -2
  109. package/permutations.js +35 -58
  110. package/pluck.js +5 -4
  111. package/push-copy.js +7 -1
  112. package/push-sort.js +9 -8
  113. package/push.js +8 -4
  114. package/range-nd.js +7 -36
  115. package/range.js +47 -51
  116. package/range2d.js +25 -22
  117. package/range3d.js +30 -27
  118. package/rechunk.js +34 -31
  119. package/reduce.js +53 -63
  120. package/reduced.js +19 -12
  121. package/reductions.js +18 -17
  122. package/rename.js +27 -16
  123. package/renamer.js +46 -52
  124. package/repeat.js +7 -19
  125. package/repeatedly.js +7 -22
  126. package/repeatedly2d.js +8 -24
  127. package/repeatedly3d.js +10 -26
  128. package/reverse.js +9 -18
  129. package/run.js +10 -8
  130. package/sample.js +17 -11
  131. package/scan.js +26 -24
  132. package/select-keys.js +5 -4
  133. package/side-effect.js +4 -8
  134. package/sliding-window.js +22 -19
  135. package/some.js +13 -9
  136. package/sorted-keys.js +5 -11
  137. package/step.js +16 -66
  138. package/str.js +10 -8
  139. package/stream-shuffle.js +41 -40
  140. package/stream-sort.js +25 -22
  141. package/struct.js +16 -4
  142. package/sub.js +5 -2
  143. package/swizzle.js +5 -4
  144. package/symmetric.js +13 -23
  145. package/take-last.js +18 -17
  146. package/take-nth.js +12 -9
  147. package/take-while.js +13 -8
  148. package/take.js +12 -12
  149. package/throttle-time.js +11 -10
  150. package/throttle.js +9 -8
  151. package/toggle.js +12 -11
  152. package/trace.js +4 -1
  153. package/transduce.js +23 -19
  154. package/tween.js +33 -94
  155. package/vals.js +8 -16
  156. package/word-wrap.js +25 -22
  157. package/wrap-sides.js +15 -31
  158. package/zip.js +15 -12
package/CHANGELOG.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Change Log
2
2
 
3
- - **Last updated**: 2023-12-03T12:13:31Z
3
+ - **Last updated**: 2023-12-11T10:07:09Z
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/add.js CHANGED
@@ -1,4 +1,7 @@
1
1
  import { __mathop } from "./internal/mathop.js";
2
- export function add(...args) {
3
- return __mathop(add, (acc, x) => acc + x, 0, args);
2
+ function add(...args) {
3
+ return __mathop(add, (acc, x) => acc + x, 0, args);
4
4
  }
5
+ export {
6
+ add
7
+ };
package/api.js CHANGED
@@ -1 +0,0 @@
1
- export {};
package/as-iterable.js CHANGED
@@ -1,9 +1,6 @@
1
- /**
2
- * Helper function / generator to (re)provide given iterable in iterator
3
- * form.
4
- *
5
- * @param src -
6
- */
7
- export function* asIterable(src) {
8
- yield* src;
1
+ function* asIterable(src) {
2
+ yield* src;
9
3
  }
4
+ export {
5
+ asIterable
6
+ };
package/assoc-map.js CHANGED
@@ -1,6 +1,10 @@
1
1
  import { reduce, reducer } from "./reduce.js";
2
- export function assocMap(xs) {
3
- return xs
4
- ? reduce(assocMap(), xs)
5
- : reducer(() => new Map(), (acc, [k, v]) => acc.set(k, v));
2
+ function assocMap(xs) {
3
+ return xs ? reduce(assocMap(), xs) : reducer(
4
+ () => /* @__PURE__ */ new Map(),
5
+ (acc, [k, v]) => acc.set(k, v)
6
+ );
6
7
  }
8
+ export {
9
+ assocMap
10
+ };
package/assoc-obj.js CHANGED
@@ -1,6 +1,10 @@
1
1
  import { reduce, reducer } from "./reduce.js";
2
- export function assocObj(xs) {
3
- return xs
4
- ? reduce(assocObj(), xs)
5
- : reducer(() => ({}), (acc, [k, v]) => ((acc[k] = v), acc));
2
+ function assocObj(xs) {
3
+ return xs ? reduce(assocObj(), xs) : reducer(
4
+ () => ({}),
5
+ (acc, [k, v]) => (acc[k] = v, acc)
6
+ );
6
7
  }
8
+ export {
9
+ assocObj
10
+ };
package/auto-obj.js CHANGED
@@ -1,7 +1,11 @@
1
1
  import { reduce, reducer } from "./reduce.js";
2
- export function autoObj(prefix, xs) {
3
- let id = 0;
4
- return xs
5
- ? reduce(autoObj(prefix), xs)
6
- : reducer(() => ({}), (acc, v) => ((acc[prefix + id++] = v), acc));
2
+ function autoObj(prefix, xs) {
3
+ let id = 0;
4
+ return xs ? reduce(autoObj(prefix), xs) : reducer(
5
+ () => ({}),
6
+ (acc, v) => (acc[prefix + id++] = v, acc)
7
+ );
7
8
  }
9
+ export {
10
+ autoObj
11
+ };
package/benchmark.js CHANGED
@@ -1,17 +1,18 @@
1
1
  import { isIterable } from "@thi.ng/checks/is-iterable";
2
2
  import { compR } from "./compr.js";
3
3
  import { iterator1 } from "./iterator.js";
4
- export function benchmark(src) {
5
- return isIterable(src)
6
- ? iterator1(benchmark(), src)
7
- : (rfn) => {
8
- const r = rfn[2];
9
- let prev = Date.now();
10
- return compR(rfn, (acc, _) => {
11
- const t = Date.now();
12
- const x = t - prev;
13
- prev = t;
14
- return r(acc, x);
15
- });
16
- };
4
+ function benchmark(src) {
5
+ return isIterable(src) ? iterator1(benchmark(), src) : (rfn) => {
6
+ const r = rfn[2];
7
+ let prev = Date.now();
8
+ return compR(rfn, (acc, _) => {
9
+ const t = Date.now();
10
+ const x = t - prev;
11
+ prev = t;
12
+ return r(acc, x);
13
+ });
14
+ };
17
15
  }
16
+ export {
17
+ benchmark
18
+ };
package/cat.js CHANGED
@@ -1,53 +1,19 @@
1
1
  import { compR } from "./compr.js";
2
2
  import { ensureReduced, isReduced, unreduced } from "./reduced.js";
3
- /**
4
- * Transducer to concatenate iterable values. Iterates over each input and emits
5
- * individual values down stream, therefore removing one level of nesting from
6
- * the input.
7
- *
8
- * @remarks
9
- * If, during processing, the transducer is given a wrapped reduced input
10
- * iterable, it will still be processed as normal, but then immediately triggers
11
- * early termination by wrapping its own result in {@link reduced}. E.g. this
12
- * behavior allows a {@link mapcat} user functions to benefit from reduced
13
- * results.
14
- *
15
- * Also see:
16
- * - {@link concat}
17
- * - {@link mapcat}
18
- *
19
- * @example
20
- * ```ts
21
- * [...iterator(comp(map((x) => [x, x]), cat()), [1, 2, 3, 4])]
22
- * // [ 1, 1, 2, 2, 3, 3, 4, 4 ]
23
- *
24
- * [...iterator(
25
- * comp(
26
- * mapIndexed((i, x) => [[i], [x, x]]),
27
- * cat(),
28
- * cat()
29
- * ),
30
- * "abc"
31
- * )]
32
- * // [ 0, 'a', 'a', 1, 'b', 'b', 2, 'c', 'c' ]
33
- *
34
- * [...mapcat((x)=>(x > 1 ? reduced([x, x]) : [x, x]), [1, 2, 3, 4])]
35
- * // [ 1, 1, 2, 2 ]
36
- * ```
37
- *
38
- * @param rfn -
39
- */
40
- export const cat = () => (rfn) => {
41
- const r = rfn[2];
42
- return compR(rfn, (acc, x) => {
43
- if (x) {
44
- for (let y of unreduced(x)) {
45
- acc = r(acc, y);
46
- if (isReduced(acc)) {
47
- break;
48
- }
49
- }
3
+ const cat = () => (rfn) => {
4
+ const r = rfn[2];
5
+ return compR(rfn, (acc, x) => {
6
+ if (x) {
7
+ for (let y of unreduced(x)) {
8
+ acc = r(acc, y);
9
+ if (isReduced(acc)) {
10
+ break;
50
11
  }
51
- return isReduced(x) ? ensureReduced(acc) : acc;
52
- });
12
+ }
13
+ }
14
+ return isReduced(x) ? ensureReduced(acc) : acc;
15
+ });
16
+ };
17
+ export {
18
+ cat
53
19
  };
package/choices.js CHANGED
@@ -2,22 +2,9 @@ import { ensureArray } from "@thi.ng/arrays/ensure-array";
2
2
  import { SYSTEM } from "@thi.ng/random/system";
3
3
  import { weightedRandom } from "@thi.ng/random/weighted-random";
4
4
  import { repeatedly } from "./repeatedly.js";
5
- /**
6
- * Returns an infinite iterator of random choices and their (optional) weights.
7
- * If `weights` is given, it must have at least the same size as `choices`. If
8
- * omitted, each choice will have same probability.
9
- *
10
- * @example
11
- * ```ts
12
- * transduce(take(1000), frequencies(), choices("abcd", [1, 0.5, 0.25, 0.125]))
13
- * // Map { 'c' => 132, 'a' => 545, 'b' => 251, 'd' => 72 }
14
- * ```
15
- *
16
- * [`weightedRandom()`](https://docs.thi.ng/umbrella/random/functions/weightedRandom.html)
17
- *
18
- * @param choices -
19
- * @param weights -
20
- */
21
- export const choices = (choices, weights, rnd = SYSTEM) => repeatedly(weights
22
- ? weightedRandom(ensureArray(choices), weights, rnd)
23
- : () => choices[rnd.float(choices.length) | 0]);
5
+ const choices = (choices2, weights, rnd = SYSTEM) => repeatedly(
6
+ weights ? weightedRandom(ensureArray(choices2), weights, rnd) : () => choices2[rnd.float(choices2.length) | 0]
7
+ );
8
+ export {
9
+ choices
10
+ };
package/comp.js CHANGED
@@ -1,6 +1,9 @@
1
1
  import { comp as _comp } from "@thi.ng/compose/comp";
2
2
  import { ensureTransducer } from "./ensure.js";
3
- export function comp(...fns) {
4
- fns = fns.map(ensureTransducer);
5
- return _comp.apply(null, fns);
3
+ function comp(...fns) {
4
+ fns = fns.map(ensureTransducer);
5
+ return _comp.apply(null, fns);
6
6
  }
7
+ export {
8
+ comp
9
+ };
package/compr.js CHANGED
@@ -1,25 +1,4 @@
1
- /**
2
- * Reducer composition helper, internally used by various transducers
3
- * during initialization. Takes existing reducer `rfn` (a 3-tuple) and a
4
- * reducing function `fn`. Returns a new reducer tuple.
5
- *
6
- * @remarks
7
- * `rfn[2]` reduces values of type `B` into an accumulator of type `A`.
8
- * `fn` accepts values of type `C` and produces interim results of type
9
- * `B`, which are then (possibly) passed to the "inner" `rfn[2]`
10
- * function. Therefore the resulting reducer takes inputs of `C` and an
11
- * accumulator of type `A`.
12
- *
13
- * It is assumed that `fn` internally calls `rfn[2]` to pass its own
14
- * results for further processing by the nested reducer `rfn`.
15
- *
16
- * @example
17
- * ```ts
18
- * compR(rfn, fn)
19
- * // [rfn[0], rfn[1], fn]
20
- * ```
21
- *
22
- * @param rfn -
23
- * @param fn -
24
- */
25
- export const compR = (rfn, fn) => [rfn[0], rfn[1], fn];
1
+ const compR = (rfn, fn) => [rfn[0], rfn[1], fn];
2
+ export {
3
+ compR
4
+ };
package/concat.js CHANGED
@@ -1,22 +1,9 @@
1
1
  import { ensureIterable } from "@thi.ng/arrays/ensure-iterable";
2
- /**
3
- * Yields iterator producing concatenation of given iterables.
4
- * Undefined & null inputs are silently ignored, however any
5
- * such values produced or contained in an input will remain.
6
- *
7
- * @example
8
- * ```ts
9
- * [...concat([1, 2, 3], null, [4, 5])]
10
- * // [ 1, 2, 3, 4, 5 ]
11
- *
12
- * [...concat([1, 2, 3, undefined], null, [4, 5])]
13
- * // [ 1, 2, 3, undefined, 4, 5 ]
14
- * ```
15
- *
16
- * @param xs -
17
- */
18
- export function* concat(...xs) {
19
- for (let x of xs) {
20
- x != null && (yield* ensureIterable(x));
21
- }
2
+ function* concat(...xs) {
3
+ for (let x of xs) {
4
+ x != null && (yield* ensureIterable(x));
5
+ }
22
6
  }
7
+ export {
8
+ concat
9
+ };
package/conj.js CHANGED
@@ -1,6 +1,10 @@
1
1
  import { reduce, reducer } from "./reduce.js";
2
- export function conj(xs) {
3
- return xs
4
- ? reduce(conj(), xs)
5
- : reducer(() => new Set(), (acc, x) => acc.add(x));
2
+ function conj(xs) {
3
+ return xs ? reduce(conj(), xs) : reducer(
4
+ () => /* @__PURE__ */ new Set(),
5
+ (acc, x) => acc.add(x)
6
+ );
6
7
  }
8
+ export {
9
+ conj
10
+ };
package/consume.js CHANGED
@@ -1,25 +1,7 @@
1
- /**
2
- * Consumes given iterable, presumably for any implicit side-effects. Iterable
3
- * MUST be finite!
4
- *
5
- * @remarks
6
- * See {@link run} for a similar approach when also side-effecting transducers
7
- * should be applied.
8
- *
9
- * @example
10
- * ```ts
11
- * consume(repeatedly2d((x, y) => console.log("output:", [x, y]), 2, 3));
12
- * // output: [ 0, 0 ]
13
- * // output: [ 1, 0 ]
14
- * // output: [ 0, 1 ]
15
- * // output: [ 1, 1 ]
16
- * // output: [ 0, 2 ]
17
- * // output: [ 1, 2 ]
18
- * ```
19
- *
20
- * @param src
21
- */
22
- export const consume = (src) => {
23
- for (let _ of src)
24
- ;
1
+ const consume = (src) => {
2
+ for (let _ of src)
3
+ ;
4
+ };
5
+ export {
6
+ consume
25
7
  };
package/converge.js CHANGED
@@ -2,20 +2,22 @@ import { SEMAPHORE } from "@thi.ng/api/api";
2
2
  import { compR } from "./compr.js";
3
3
  import { __iter } from "./iterator.js";
4
4
  import { ensureReduced } from "./reduced.js";
5
- export function converge(...args) {
6
- return (__iter(converge, args) ||
7
- ((rfn) => {
8
- const r = rfn[2];
9
- const pred = args[0];
10
- let prev = SEMAPHORE;
11
- let done = false;
12
- return compR(rfn, (acc, x) => {
13
- if (done || (prev !== SEMAPHORE && pred(prev, x))) {
14
- done = true;
15
- return ensureReduced(r(acc, x));
16
- }
17
- prev = x;
18
- return r(acc, x);
19
- });
20
- }));
5
+ function converge(...args) {
6
+ return __iter(converge, args) || ((rfn) => {
7
+ const r = rfn[2];
8
+ const pred = args[0];
9
+ let prev = SEMAPHORE;
10
+ let done = false;
11
+ return compR(rfn, (acc, x) => {
12
+ if (done || prev !== SEMAPHORE && pred(prev, x)) {
13
+ done = true;
14
+ return ensureReduced(r(acc, x));
15
+ }
16
+ prev = x;
17
+ return r(acc, x);
18
+ });
19
+ });
21
20
  }
21
+ export {
22
+ converge
23
+ };
package/convolve.js CHANGED
@@ -6,62 +6,74 @@ import { range } from "./range.js";
6
6
  import { range2d } from "./range2d.js";
7
7
  import { transduce } from "./transduce.js";
8
8
  import { zip } from "./zip.js";
9
- export const buildKernel1d = (weights, w) => {
10
- const w2 = w >> 1;
11
- return [...zip(weights, range(-w2, w2 + 1))];
9
+ const buildKernel1d = (weights, w) => {
10
+ const w2 = w >> 1;
11
+ return [...zip(weights, range(-w2, w2 + 1))];
12
12
  };
13
- export const buildKernel2d = (weights, w, h = w) => {
14
- const w2 = w >> 1;
15
- const h2 = h >> 1;
16
- return [...zip(weights, range2d(-w2, w2 + 1, -h2, h2 + 1))];
13
+ const buildKernel2d = (weights, w, h = w) => {
14
+ const w2 = w >> 1;
15
+ const h2 = h >> 1;
16
+ return [...zip(weights, range2d(-w2, w2 + 1, -h2, h2 + 1))];
17
+ };
18
+ const kernelLookup1d = (src, x, width, wrap, border) => wrap ? ({ 0: w, 1: ox }) => {
19
+ const xx = x < -ox ? width + ox : x >= width - ox ? ox - 1 : x + ox;
20
+ return w * src[xx];
21
+ } : ({ 0: w, 1: ox }) => {
22
+ return x < -ox || x >= width - ox ? border : w * src[x + ox];
23
+ };
24
+ const kernelLookup2d = (src, x, y, width, height, wrap, border) => wrap ? ({ 0: w, 1: { 0: ox, 1: oy } }) => {
25
+ const xx = x < -ox ? width + ox : x >= width - ox ? ox - 1 : x + ox;
26
+ const yy = y < -oy ? height + oy : y >= height - oy ? oy - 1 : y + oy;
27
+ return w * src[yy * width + xx];
28
+ } : ({ 0: w, 1: { 0: ox, 1: oy } }) => {
29
+ return x < -ox || y < -oy || x >= width - ox || y >= height - oy ? border : w * src[(y + oy) * width + x + ox];
17
30
  };
18
- const kernelLookup1d = (src, x, width, wrap, border) => wrap
19
- ? ({ 0: w, 1: ox }) => {
20
- const xx = x < -ox ? width + ox : x >= width - ox ? ox - 1 : x + ox;
21
- return w * src[xx];
22
- }
23
- : ({ 0: w, 1: ox }) => {
24
- return x < -ox || x >= width - ox ? border : w * src[x + ox];
25
- };
26
- const kernelLookup2d = (src, x, y, width, height, wrap, border) => wrap
27
- ? ({ 0: w, 1: { 0: ox, 1: oy } }) => {
28
- const xx = x < -ox ? width + ox : x >= width - ox ? ox - 1 : x + ox;
29
- const yy = y < -oy ? height + oy : y >= height - oy ? oy - 1 : y + oy;
30
- return w * src[yy * width + xx];
31
- }
32
- : ({ 0: w, 1: { 0: ox, 1: oy } }) => {
33
- return x < -ox || y < -oy || x >= width - ox || y >= height - oy
34
- ? border
35
- : w * src[(y + oy) * width + x + ox];
36
- };
37
31
  const kernelError = () => illegalArgs(`no kernel or kernel config`);
38
- export function convolve1d(opts, indices) {
39
- if (indices) {
40
- return iterator1(convolve1d(opts), indices);
41
- }
42
- const { src, width } = opts;
43
- const wrap = opts.wrap !== false;
44
- const border = opts.border || 0;
45
- const rfn = opts.reduce || add;
46
- let kernel = opts.kernel;
47
- if (!kernel) {
48
- !(opts.weights && opts.kwidth) && kernelError();
49
- kernel = buildKernel1d(opts.weights, opts.kwidth);
50
- }
51
- return map((p) => transduce(map(kernelLookup1d(src, p, width, wrap, border)), rfn(), kernel));
32
+ function convolve1d(opts, indices) {
33
+ if (indices) {
34
+ return iterator1(convolve1d(opts), indices);
35
+ }
36
+ const { src, width } = opts;
37
+ const wrap = opts.wrap !== false;
38
+ const border = opts.border || 0;
39
+ const rfn = opts.reduce || add;
40
+ let kernel = opts.kernel;
41
+ if (!kernel) {
42
+ !(opts.weights && opts.kwidth) && kernelError();
43
+ kernel = buildKernel1d(opts.weights, opts.kwidth);
44
+ }
45
+ return map(
46
+ (p) => transduce(
47
+ map(kernelLookup1d(src, p, width, wrap, border)),
48
+ rfn(),
49
+ kernel
50
+ )
51
+ );
52
52
  }
53
- export function convolve2d(opts, indices) {
54
- if (indices) {
55
- return iterator1(convolve2d(opts), indices);
56
- }
57
- const { src, width, height } = opts;
58
- const wrap = opts.wrap !== false;
59
- const border = opts.border || 0;
60
- const rfn = opts.reduce || add;
61
- let kernel = opts.kernel;
62
- if (!kernel) {
63
- !(opts.weights && opts.kwidth && opts.kheight) && kernelError();
64
- kernel = buildKernel2d(opts.weights, opts.kwidth, opts.kheight);
65
- }
66
- return map((p) => transduce(map(kernelLookup2d(src, p[0], p[1], width, height, wrap, border)), rfn(), kernel));
53
+ function convolve2d(opts, indices) {
54
+ if (indices) {
55
+ return iterator1(convolve2d(opts), indices);
56
+ }
57
+ const { src, width, height } = opts;
58
+ const wrap = opts.wrap !== false;
59
+ const border = opts.border || 0;
60
+ const rfn = opts.reduce || add;
61
+ let kernel = opts.kernel;
62
+ if (!kernel) {
63
+ !(opts.weights && opts.kwidth && opts.kheight) && kernelError();
64
+ kernel = buildKernel2d(opts.weights, opts.kwidth, opts.kheight);
65
+ }
66
+ return map(
67
+ (p) => transduce(
68
+ map(kernelLookup2d(src, p[0], p[1], width, height, wrap, border)),
69
+ rfn(),
70
+ kernel
71
+ )
72
+ );
67
73
  }
74
+ export {
75
+ buildKernel1d,
76
+ buildKernel2d,
77
+ convolve1d,
78
+ convolve2d
79
+ };
package/count.js CHANGED
@@ -1,10 +1,16 @@
1
1
  import { $$reduce, reducer } from "./reduce.js";
2
- export function count(...args) {
3
- const res = $$reduce(count, args);
4
- if (res !== undefined) {
5
- return res;
6
- }
7
- let offset = args[0] || 0;
8
- let step = args[1] || 1;
9
- return reducer(() => offset, (acc, _) => acc + step);
2
+ function count(...args) {
3
+ const res = $$reduce(count, args);
4
+ if (res !== void 0) {
5
+ return res;
6
+ }
7
+ let offset = args[0] || 0;
8
+ let step = args[1] || 1;
9
+ return reducer(
10
+ () => offset,
11
+ (acc, _) => acc + step
12
+ );
10
13
  }
14
+ export {
15
+ count
16
+ };
package/curve.js CHANGED
@@ -1,46 +1,13 @@
1
- /**
2
- * Iterator producing an exponential curve (with adjustable curvature) between
3
- * `start` and `end` values over `num` steps. This is the exponential equivalent
4
- * of {@link line}.
5
- *
6
- * @remarks
7
- * Since `start` is the first value emitted, the `end` value is only reached in
8
- * the `num+1`th step.
9
- *
10
- * The curvature can be controlled via the logarithmic `rate` param. Recommended
11
- * range [0.0001 - 10000] (curved -> linear). Default: 0.1
12
- *
13
- * Similar functionality (w/ more options) is availble here:
14
- * [`curve()`](https://docs.thi.ng/umbrella/dsp/functions/curve.html).
15
- *
16
- * @example
17
- * ```ts
18
- * [...curve(50, 100, 10, 2)]
19
- * // [
20
- * // 50,
21
- * // 73.193,
22
- * // 85.649,
23
- * // 92.339,
24
- * // 95.932,
25
- * // 97.861,
26
- * // 98.897,
27
- * // 99.454,
28
- * // 99.753,
29
- * // 99.913,
30
- * // 100
31
- * // ]
32
- * ```
33
- *
34
- * @param start -
35
- * @param end -
36
- * @param steps -
37
- * @param falloff -
38
- */
39
- export function* curve(start, end, steps = 10, rate = 0.1) {
40
- const c = Math.exp(-Math.log((Math.abs(end - start) + rate) / rate) / steps);
41
- const offset = (start < end ? end + rate : end - rate) * (1 - c);
42
- steps > 0 && (yield start);
43
- for (let x = start; steps-- > 0;) {
44
- yield (x = offset + x * c);
45
- }
1
+ function* curve(start, end, steps = 10, rate = 0.1) {
2
+ const c = Math.exp(
3
+ -Math.log((Math.abs(end - start) + rate) / rate) / steps
4
+ );
5
+ const offset = (start < end ? end + rate : end - rate) * (1 - c);
6
+ steps > 0 && (yield start);
7
+ for (let x = start; steps-- > 0; ) {
8
+ yield x = offset + x * c;
9
+ }
46
10
  }
11
+ export {
12
+ curve
13
+ };
package/cycle.js CHANGED
@@ -1,36 +1,17 @@
1
- /**
2
- * Iterator which yields an infinite repetition of given `input`
3
- * iterable's values. Produces no values if `input` is empty. If `num`
4
- * is given, only that many cycles will be emitted.
5
- *
6
- * @remarks
7
- * Also see {@link repeat}, {@link repeatedly} for related functions.
8
- *
9
- * @example
10
- * ```ts
11
- * // take 5 from infinite sequence
12
- * [...take(5, cycle([1, 2, 3]))]
13
- * // [1, 2, 3, 1, 2]
14
- *
15
- * // only produce 2 cycles
16
- * [...cycle(range(3), 2)]
17
- * // [ 0, 1, 2, 0, 1, 2 ]
18
- * ```
19
- *
20
- * @param input -
21
- * @param num -
22
- */
23
- export function* cycle(input, num = Infinity) {
24
- if (num < 1)
25
- return;
26
- let cache = [];
27
- for (let i of input) {
28
- cache.push(i);
29
- yield i;
30
- }
31
- if (cache.length > 0) {
32
- while (--num > 0) {
33
- yield* cache;
34
- }
1
+ function* cycle(input, num = Infinity) {
2
+ if (num < 1)
3
+ return;
4
+ let cache = [];
5
+ for (let i of input) {
6
+ cache.push(i);
7
+ yield i;
8
+ }
9
+ if (cache.length > 0) {
10
+ while (--num > 0) {
11
+ yield* cache;
35
12
  }
13
+ }
36
14
  }
15
+ export {
16
+ cycle
17
+ };