@thi.ng/transducers 9.5.0 → 9.6.0

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**: 2025-07-09T09:42:08Z
3
+ - **Last updated**: 2025-07-13T21:35:34Z
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.
@@ -11,6 +11,19 @@ See [Conventional Commits](https://conventionalcommits.org/) for commit guidelin
11
11
  **Note:** Unlisted _patch_ versions only involve non-code or otherwise excluded changes
12
12
  and/or version bumps of transitive dependencies.
13
13
 
14
+ ## [9.6.0](https://github.com/thi-ng/umbrella/tree/@thi.ng/transducers@9.6.0) (2025-07-13)
15
+
16
+ #### 🚀 Features
17
+
18
+ - add result caching for `step()` ([101760b](https://github.com/thi-ng/umbrella/commit/101760b))
19
+ - update `StepFn` type, add `IDeref` support
20
+ - update `step()` to cache most recent result (can be disabled)
21
+
22
+ #### ♻️ Refactoring
23
+
24
+ - minor update `multiplex()` ([d2cae35](https://github.com/thi-ng/umbrella/commit/d2cae35))
25
+ - disable result caching for internal`step()` usage to reduce RAM usage
26
+
14
27
  ## [9.5.0](https://github.com/thi-ng/umbrella/tree/@thi.ng/transducers@9.5.0) (2025-07-09)
15
28
 
16
29
  #### 🚀 Features
package/README.md CHANGED
@@ -150,7 +150,7 @@ For Node.js REPL:
150
150
  const tx = await import("@thi.ng/transducers");
151
151
  ```
152
152
 
153
- Package sizes (brotli'd, pre-treeshake): ESM: 9.21 KB
153
+ Package sizes (brotli'd, pre-treeshake): ESM: 9.22 KB
154
154
 
155
155
  ## Dependencies
156
156
 
package/multiplex.js CHANGED
@@ -6,7 +6,7 @@ function multiplex(...args) {
6
6
  juxt.apply(
7
7
  null,
8
8
  args.map(
9
- (xf) => Array.isArray(xf) ? step(xf[0], xf[1]) : step(xf)
9
+ (xf) => Array.isArray(xf) ? step(xf[0], xf[1], false) : step(xf, true, false)
10
10
  )
11
11
  )
12
12
  );
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@thi.ng/transducers",
3
- "version": "9.5.0",
3
+ "version": "9.6.0",
4
4
  "description": "Collection of ~170 lightweight, composable transducers, reducers, generators, iterators for functional data transformations",
5
5
  "type": "module",
6
6
  "module": "./index.js",
@@ -43,19 +43,19 @@
43
43
  "tool:tangle": "../../node_modules/.bin/tangle src/**/*.ts"
44
44
  },
45
45
  "dependencies": {
46
- "@thi.ng/api": "^8.11.29",
47
- "@thi.ng/arrays": "^2.13.1",
48
- "@thi.ng/checks": "^3.7.9",
49
- "@thi.ng/compare": "^2.4.21",
50
- "@thi.ng/compose": "^3.0.32",
51
- "@thi.ng/errors": "^2.5.35",
52
- "@thi.ng/math": "^5.11.29",
53
- "@thi.ng/random": "^4.1.20",
54
- "@thi.ng/timestamp": "^1.1.14"
46
+ "@thi.ng/api": "^8.11.30",
47
+ "@thi.ng/arrays": "^2.13.2",
48
+ "@thi.ng/checks": "^3.7.10",
49
+ "@thi.ng/compare": "^2.4.22",
50
+ "@thi.ng/compose": "^3.0.33",
51
+ "@thi.ng/errors": "^2.5.36",
52
+ "@thi.ng/math": "^5.11.30",
53
+ "@thi.ng/random": "^4.1.21",
54
+ "@thi.ng/timestamp": "^1.1.15"
55
55
  },
56
56
  "devDependencies": {
57
- "esbuild": "^0.25.5",
58
- "typedoc": "^0.28.5",
57
+ "esbuild": "^0.25.6",
58
+ "typedoc": "^0.28.7",
59
59
  "typescript": "^5.8.3"
60
60
  },
61
61
  "keywords": [
@@ -609,5 +609,5 @@
609
609
  ],
610
610
  "year": 2016
611
611
  },
612
- "gitHead": "e657c2d66574c18343a6797aef4585945729093e\n"
612
+ "gitHead": "a81765bd79046980463c56a8bd187f9aaa88dd65\n"
613
613
  }
package/step.d.ts CHANGED
@@ -1,14 +1,18 @@
1
- import type { Fn, Maybe } from "@thi.ng/api";
1
+ import type { Fn, IDeref, Maybe } from "@thi.ng/api";
2
2
  import type { TxLike } from "./api.js";
3
3
  /**
4
- * Type of the function produced by {@link step}.
4
+ * Type of the function produced by {@link step}. Unless disabled, by default
5
+ * the most recent result (if any) will be cached and can be (re)obtained via
6
+ * `.deref()`.
5
7
  */
6
- export type StepFn<A, B> = Fn<A, Maybe<B | B[]>>;
8
+ export type StepFn<A, B> = Fn<A, Maybe<B | B[]>> & IDeref<Maybe<B | B[]>>;
7
9
  /**
8
10
  * Single-step transducer execution wrapper. Returns array if the given
9
11
  * transducer produces multiple results and undefined if there was no output. If
10
- * the transducer only produces a single result (per step) and if `unwrap`
11
- * is true (default), the function returns that single result value itself.
12
+ * the transducer only produces a single result (per step) and if `unwrap` is
13
+ * true (default), the function returns that single result value itself. Unless
14
+ * `cache` is set to false, by default the most recent result (if any) will be
15
+ * cached and can be (re)obtained via `.deref()`.
12
16
  *
13
17
  * @remarks
14
18
  * Likewise, once a transducer has produced a final / reduced value, all further
@@ -69,6 +73,7 @@ export type StepFn<A, B> = Fn<A, Maybe<B | B[]>>;
69
73
  *
70
74
  * @param tx -
71
75
  * @param unwrap -
76
+ * @param cache -
72
77
  */
73
- export declare const step: <A, B>(tx: TxLike<A, B>, unwrap?: boolean) => StepFn<A, B>;
78
+ export declare const step: <A, B>(tx: TxLike<A, B>, unwrap?: boolean, cache?: boolean) => StepFn<A, B>;
74
79
  //# sourceMappingURL=step.d.ts.map
package/step.js CHANGED
@@ -1,19 +1,24 @@
1
1
  import { ensureTransducer } from "./ensure.js";
2
2
  import { push } from "./push.js";
3
3
  import { isReduced } from "./reduced.js";
4
- const step = (tx, unwrap = true) => {
4
+ const step = (tx, unwrap = true, cache = true) => {
5
5
  const [_, complete, reduce] = ensureTransducer(tx)(push());
6
6
  let done = false;
7
- return (x) => {
7
+ let result;
8
+ const fn = (x) => {
8
9
  if (!done) {
9
10
  let acc = reduce([], x);
10
11
  done = isReduced(acc);
11
12
  if (done) {
12
13
  acc = complete(acc.deref());
13
14
  }
14
- return acc.length === 1 && unwrap ? acc[0] : acc.length > 0 ? acc : void 0;
15
+ const res = acc.length === 1 && unwrap ? acc[0] : acc.length > 0 ? acc : void 0;
16
+ if (cache) result = res;
17
+ return res;
15
18
  }
16
19
  };
20
+ fn.deref = () => result;
21
+ return fn;
17
22
  };
18
23
  export {
19
24
  step