@thi.ng/transducers 8.7.2 → 8.8.1

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.
package/CHANGELOG.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Change Log
2
2
 
3
- - **Last updated**: 2023-09-19T10:42:50Z
3
+ - **Last updated**: 2023-10-12T11:53: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.
@@ -9,6 +9,13 @@ See [Conventional Commits](https://conventionalcommits.org/) for commit guidelin
9
9
  **Note:** Unlisted _patch_ versions only involve non-code or otherwise excluded changes
10
10
  and/or version bumps of transitive dependencies.
11
11
 
12
+ ## [8.8.0](https://github.com/thi-ng/umbrella/tree/@thi.ng/transducers@8.8.0) (2023-10-11)
13
+
14
+ #### 🚀 Features
15
+
16
+ - add repeatedly2d/3d() iterators ([5057939](https://github.com/thi-ng/umbrella/commit/5057939))
17
+ - add consume() helper fn ([e612846](https://github.com/thi-ng/umbrella/commit/e612846))
18
+
12
19
  ## [8.7.0](https://github.com/thi-ng/umbrella/tree/@thi.ng/transducers@8.7.0) (2023-09-15)
13
20
 
14
21
  #### 🚀 Features
package/README.md CHANGED
@@ -52,6 +52,7 @@ This project is part of the
52
52
  - [transduce](#transduce)
53
53
  - [transduceRight](#transduceright)
54
54
  - [run](#run)
55
+ - [consume](#consume)
55
56
  - [Transducers](#transducers)
56
57
  - [Generators / Iterators](#generators--iterators)
57
58
  - [Reducers](#reducers)
@@ -174,7 +175,7 @@ For Node.js REPL:
174
175
  const transducers = await import("@thi.ng/transducers");
175
176
  ```
176
177
 
177
- Package sizes (brotli'd, pre-treeshake): ESM: 8.71 KB
178
+ Package sizes (brotli'd, pre-treeshake): ESM: 8.78 KB
178
179
 
179
180
  ## Dependencies
180
181
 
@@ -201,6 +202,7 @@ A selection:
201
202
  | <img src="https://raw.githubusercontent.com/thi-ng/umbrella/develop/assets/examples/ascii-raymarch.jpg" width="240"/> | ASCII art raymarching with thi.ng/shader-ast & thi.ng/text-canvas | [Demo](https://demo.thi.ng/umbrella/ascii-raymarch/) | [Source](https://github.com/thi-ng/umbrella/tree/develop/examples/ascii-raymarch) |
202
203
  | <img src="https://raw.githubusercontent.com/thi-ng/umbrella/develop/assets/examples/big-font.png" width="240"/> | Large ASCII font text generator using @thi.ng/rdom | [Demo](https://demo.thi.ng/umbrella/big-font/) | [Source](https://github.com/thi-ng/umbrella/tree/develop/examples/big-font) |
203
204
  | <img src="https://raw.githubusercontent.com/thi-ng/umbrella/develop/assets/examples/bitmap-font.gif" width="240"/> | Figlet-style bitmap font creation with transducers | [Demo](https://demo.thi.ng/umbrella/bitmap-font/) | [Source](https://github.com/thi-ng/umbrella/tree/develop/examples/bitmap-font) |
205
+ | <img src="https://raw.githubusercontent.com/thi-ng/umbrella/develop/assets/examples/canvas-recorder.png" width="240"/> | Self-modifying, animated typographic grid with emergent complex patterns | [Demo](https://demo.thi.ng/umbrella/canvas-recorder/) | [Source](https://github.com/thi-ng/umbrella/tree/develop/examples/canvas-recorder) |
204
206
  | <img src="https://raw.githubusercontent.com/thi-ng/umbrella/develop/assets/examples/cellular-automata.png" width="240"/> | 2D transducer based cellular automata | [Demo](https://demo.thi.ng/umbrella/cellular-automata/) | [Source](https://github.com/thi-ng/umbrella/tree/develop/examples/cellular-automata) |
205
207
  | <img src="https://raw.githubusercontent.com/thi-ng/umbrella/develop/assets/examples/commit-heatmap.png" width="240"/> | Heatmap visualization of this mono-repo's commits | | [Source](https://github.com/thi-ng/umbrella/tree/develop/examples/commit-heatmap) |
206
208
  | <img src="https://raw.githubusercontent.com/thi-ng/umbrella/develop/assets/examples/commit-table-ssr.png" width="240"/> | Filterable commit log UI w/ minimal server to provide commit history | [Demo](https://demo.thi.ng/umbrella/commit-table-ssr/) | [Source](https://github.com/thi-ng/umbrella/tree/develop/examples/commit-table-ssr) |
@@ -225,6 +227,7 @@ A selection:
225
227
  | <img src="https://raw.githubusercontent.com/thi-ng/umbrella/develop/assets/examples/package-stats.png" width="240"/> | CLI util to visualize umbrella pkg stats | | [Source](https://github.com/thi-ng/umbrella/tree/develop/examples/package-stats) |
226
228
  | <img src="https://raw.githubusercontent.com/thi-ng/umbrella/develop/assets/examples/parse-playground.png" width="240"/> | Parser grammar livecoding editor/playground & codegen | [Demo](https://demo.thi.ng/umbrella/parse-playground/) | [Source](https://github.com/thi-ng/umbrella/tree/develop/examples/parse-playground) |
227
229
  | <img src="https://raw.githubusercontent.com/thi-ng/umbrella/develop/assets/examples/poly-spline.png" width="240"/> | Polygon to cubic curve conversion & visualization | [Demo](https://demo.thi.ng/umbrella/poly-spline/) | [Source](https://github.com/thi-ng/umbrella/tree/develop/examples/poly-spline) |
230
+ | <img src="https://raw.githubusercontent.com/thi-ng/umbrella/develop/assets/examples/poly-subdiv.jpg" width="240"/> | Animated, iterative polygon subdivisions & visualization | [Demo](https://demo.thi.ng/umbrella/poly-subdiv/) | [Source](https://github.com/thi-ng/umbrella/tree/develop/examples/poly-subdiv) |
228
231
  | <img src="https://raw.githubusercontent.com/thi-ng/umbrella/develop/assets/examples/ramp-synth.png" width="240"/> | Unison wavetable synth with waveform editor | [Demo](https://demo.thi.ng/umbrella/ramp-synth/) | [Source](https://github.com/thi-ng/umbrella/tree/develop/examples/ramp-synth) |
229
232
  | | Demonstates various rdom usage patterns | [Demo](https://demo.thi.ng/umbrella/rdom-basics/) | [Source](https://github.com/thi-ng/umbrella/tree/develop/examples/rdom-basics) |
230
233
  | <img src="https://raw.githubusercontent.com/thi-ng/umbrella/develop/assets/examples/rdom-canvas-basics.jpg" width="240"/> | Minimal rdom-canvas animation | [Demo](https://demo.thi.ng/umbrella/rdom-canvas-basics/) | [Source](https://github.com/thi-ng/umbrella/tree/develop/examples/rdom-canvas-basics) |
@@ -851,6 +854,26 @@ every value produced by the transducer. If `fx` is _not_ given, the
851
854
  transducer is assumed to include at least one `sideEffect()` step
852
855
  itself. Returns nothing.
853
856
 
857
+ #### consume
858
+
859
+ `consume(src: Iterable<any>): void`
860
+
861
+ Similar to `run()`, consumes given iterable, presumably for any implicit
862
+ side-effects. Iterable MUST be finite!
863
+
864
+ ```ts
865
+ // here the function given to repeatedly2d() has only a side-effect, however
866
+ // repeatedly2d() itself is lazy. Using consume() then forces this lazy iterator/generator
867
+ // to be realized and so also the side-effects to be executed
868
+ consume(repeatedly2d((x, y) => console.log("output:", [x, y]), 2, 3));
869
+ // output: [ 0, 0 ]
870
+ // output: [ 1, 0 ]
871
+ // output: [ 0, 1 ]
872
+ // output: [ 1, 1 ]
873
+ // output: [ 0, 2 ]
874
+ // output: [ 1, 2 ]
875
+ ```
876
+
854
877
  ### Transducers
855
878
 
856
879
  All of the following functions can be used and composed as transducers.
@@ -964,6 +987,8 @@ transduce(map((x) => x*10), push(), range(4))
964
987
  - [rangeNd](https://github.com/thi-ng/umbrella/tree/develop/packages/transducers/src/range-nd.ts)
965
988
  - [repeat](https://github.com/thi-ng/umbrella/tree/develop/packages/transducers/src/repeat.ts)
966
989
  - [repeatedly](https://github.com/thi-ng/umbrella/tree/develop/packages/transducers/src/repeatedly.ts)
990
+ - [repeatedly2d](https://github.com/thi-ng/umbrella/tree/develop/packages/transducers/src/repeatedly2d.ts)
991
+ - [repeatedly3d](https://github.com/thi-ng/umbrella/tree/develop/packages/transducers/src/repeatedly3d.ts)
967
992
  - [reverse](https://github.com/thi-ng/umbrella/tree/develop/packages/transducers/src/reverse.ts)
968
993
  - [sortedKeys](https://github.com/thi-ng/umbrella/tree/develop/packages/transducers/src/sorted-keys.ts)
969
994
  - [symmetric](https://github.com/thi-ng/umbrella/tree/develop/packages/transducers/src/symmetric.ts)
package/consume.d.ts ADDED
@@ -0,0 +1,23 @@
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 declare const consume: (src: Iterable<any>) => void;
23
+ //# sourceMappingURL=consume.d.ts.map
package/consume.js ADDED
@@ -0,0 +1,25 @@
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
+ ;
25
+ };
package/index.d.ts CHANGED
@@ -8,6 +8,7 @@ export * from "./step.js";
8
8
  export * from "./transduce.js";
9
9
  export * from "./comp.js";
10
10
  export * from "./compr.js";
11
+ export * from "./consume.js";
11
12
  export * from "./deep-transform.js";
12
13
  export * from "./juxtr.js";
13
14
  export * from "./lookup.js";
@@ -139,6 +140,8 @@ export * from "./range3d.js";
139
140
  export * from "./range-nd.js";
140
141
  export * from "./repeat.js";
141
142
  export * from "./repeatedly.js";
143
+ export * from "./repeatedly2d.js";
144
+ export * from "./repeatedly3d.js";
142
145
  export * from "./reverse.js";
143
146
  export * from "./sorted-keys.js";
144
147
  export * from "./symmetric.js";
package/index.js CHANGED
@@ -9,6 +9,7 @@ export * from "./transduce.js";
9
9
  // helpers
10
10
  export * from "./comp.js";
11
11
  export * from "./compr.js";
12
+ export * from "./consume.js";
12
13
  export * from "./deep-transform.js";
13
14
  export * from "./juxtr.js";
14
15
  export * from "./lookup.js";
@@ -143,6 +144,8 @@ export * from "./range3d.js";
143
144
  export * from "./range-nd.js";
144
145
  export * from "./repeat.js";
145
146
  export * from "./repeatedly.js";
147
+ export * from "./repeatedly2d.js";
148
+ export * from "./repeatedly3d.js";
146
149
  export * from "./reverse.js";
147
150
  export * from "./sorted-keys.js";
148
151
  export * from "./symmetric.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@thi.ng/transducers",
3
- "version": "8.7.2",
3
+ "version": "8.8.1",
4
4
  "description": "Lightweight transducer implementations for ES6 / TypeScript",
5
5
  "type": "module",
6
6
  "module": "./index.js",
@@ -39,13 +39,13 @@
39
39
  },
40
40
  "dependencies": {
41
41
  "@thi.ng/api": "^8.9.5",
42
- "@thi.ng/arrays": "^2.6.0",
42
+ "@thi.ng/arrays": "^2.6.2",
43
43
  "@thi.ng/checks": "^3.4.5",
44
44
  "@thi.ng/compare": "^2.2.0",
45
- "@thi.ng/compose": "^2.1.41",
45
+ "@thi.ng/compose": "^2.1.42",
46
46
  "@thi.ng/errors": "^2.3.5",
47
- "@thi.ng/math": "^5.6.1",
48
- "@thi.ng/random": "^3.6.6"
47
+ "@thi.ng/math": "^5.6.2",
48
+ "@thi.ng/random": "^3.6.8"
49
49
  },
50
50
  "devDependencies": {
51
51
  "@microsoft/api-extractor": "^7.36.4",
@@ -147,6 +147,9 @@
147
147
  "./conj": {
148
148
  "default": "./conj.js"
149
149
  },
150
+ "./consume": {
151
+ "default": "./consume.js"
152
+ },
150
153
  "./converge": {
151
154
  "default": "./converge.js"
152
155
  },
@@ -459,6 +462,12 @@
459
462
  "./repeatedly": {
460
463
  "default": "./repeatedly.js"
461
464
  },
465
+ "./repeatedly2d": {
466
+ "default": "./repeatedly2d.js"
467
+ },
468
+ "./repeatedly3d": {
469
+ "default": "./repeatedly3d.js"
470
+ },
462
471
  "./reverse": {
463
472
  "default": "./reverse.js"
464
473
  },
@@ -579,5 +588,5 @@
579
588
  ],
580
589
  "year": 2016
581
590
  },
582
- "gitHead": "10d8b3725e96c5d704c759489a89f132892b181e\n"
591
+ "gitHead": "d492ecb41df758db372a76449ea9b5bad47b25c4\n"
583
592
  }
@@ -0,0 +1,22 @@
1
+ import type { FnU2 } from "@thi.ng/api";
2
+ /**
3
+ * Syntax sugar for `map(fn, range2d(cols, rows))`. Returns iterator yielding
4
+ * values of given 2-arg function `fn` which is called repeatedly with `x` and
5
+ * `y` grid coordinates. The iteration order is always row-major.
6
+ *
7
+ * @example
8
+ * ```ts
9
+ * [...repeatedly2d((x, y) => [(x + 1) * 10, (y + 1) * 100], 2, 3)]
10
+ * // [
11
+ * // [ 10, 100 ], [ 20, 100 ],
12
+ * // [ 10, 200 ], [ 20, 200 ],
13
+ * // [ 10, 300 ], [ 20, 300 ]
14
+ * // ]
15
+ * ```
16
+ *
17
+ * @param fn - value producer
18
+ * @param cols - number of columns
19
+ * @param rows - number of rows
20
+ */
21
+ export declare function repeatedly2d<T>(fn: FnU2<number, T>, cols: number, rows: number): Generator<T, void, unknown>;
22
+ //# sourceMappingURL=repeatedly2d.d.ts.map
@@ -0,0 +1,26 @@
1
+ /**
2
+ * Syntax sugar for `map(fn, range2d(cols, rows))`. Returns iterator yielding
3
+ * values of given 2-arg function `fn` which is called repeatedly with `x` and
4
+ * `y` grid coordinates. The iteration order is always row-major.
5
+ *
6
+ * @example
7
+ * ```ts
8
+ * [...repeatedly2d((x, y) => [(x + 1) * 10, (y + 1) * 100], 2, 3)]
9
+ * // [
10
+ * // [ 10, 100 ], [ 20, 100 ],
11
+ * // [ 10, 200 ], [ 20, 200 ],
12
+ * // [ 10, 300 ], [ 20, 300 ]
13
+ * // ]
14
+ * ```
15
+ *
16
+ * @param fn - value producer
17
+ * @param cols - number of columns
18
+ * @param rows - number of rows
19
+ */
20
+ export function* repeatedly2d(fn, cols, rows) {
21
+ for (let y = 0; y < rows; y++) {
22
+ for (let x = 0; x < cols; x++) {
23
+ yield fn(x, y);
24
+ }
25
+ }
26
+ }
@@ -0,0 +1,22 @@
1
+ import type { FnU3 } from "@thi.ng/api";
2
+ /**
3
+ * Syntax sugar for `map(fn, range3d(cols, rows, slices))`. Returns iterator yielding
4
+ * values of given 3-arg function `fn` which is called repeatedly with `x`, `y` and
5
+ * `z` grid coordinates. The iteration order is always slice major, then row-major.
6
+ *
7
+ * @example
8
+ * ```ts
9
+ * [...repeatedly3d((x, y, z) => [(x+1)*10, (y+1)*100, (z+1)*1000], 2, 2, 2)]
10
+ * // [
11
+ * // [ 10, 100, 1000 ], [ 20, 100, 1000 ], [ 10, 200, 1000 ], [ 20, 200, 1000 ],
12
+ * // [ 10, 100, 2000 ], [ 20, 100, 2000 ], [ 10, 200, 2000 ], [ 20, 200, 2000 ]
13
+ * // ]
14
+ * ```
15
+ *
16
+ * @param fn - value producer
17
+ * @param cols - number of columns
18
+ * @param rows - number of rows
19
+ * @param slices - number of slices
20
+ */
21
+ export declare function repeatedly3d<T>(fn: FnU3<number, T>, cols: number, rows: number, slices: number): Generator<T, void, unknown>;
22
+ //# sourceMappingURL=repeatedly3d.d.ts.map
@@ -0,0 +1,28 @@
1
+ /**
2
+ * Syntax sugar for `map(fn, range3d(cols, rows, slices))`. Returns iterator yielding
3
+ * values of given 3-arg function `fn` which is called repeatedly with `x`, `y` and
4
+ * `z` grid coordinates. The iteration order is always slice major, then row-major.
5
+ *
6
+ * @example
7
+ * ```ts
8
+ * [...repeatedly3d((x, y, z) => [(x+1)*10, (y+1)*100, (z+1)*1000], 2, 2, 2)]
9
+ * // [
10
+ * // [ 10, 100, 1000 ], [ 20, 100, 1000 ], [ 10, 200, 1000 ], [ 20, 200, 1000 ],
11
+ * // [ 10, 100, 2000 ], [ 20, 100, 2000 ], [ 10, 200, 2000 ], [ 20, 200, 2000 ]
12
+ * // ]
13
+ * ```
14
+ *
15
+ * @param fn - value producer
16
+ * @param cols - number of columns
17
+ * @param rows - number of rows
18
+ * @param slices - number of slices
19
+ */
20
+ export function* repeatedly3d(fn, cols, rows, slices) {
21
+ for (let z = 0; z < slices; z++) {
22
+ for (let y = 0; y < rows; y++) {
23
+ for (let x = 0; x < cols; x++) {
24
+ yield fn(x, y, z);
25
+ }
26
+ }
27
+ }
28
+ }