@thi.ng/transducers 9.2.26 β†’ 9.3.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-04-16T11:11:14Z
3
+ - **Last updated**: 2025-04-30T12:52:32Z
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,12 @@ 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.3.0](https://github.com/thi-ng/umbrella/tree/@thi.ng/transducers@9.3.0) (2025-04-30)
15
+
16
+ #### πŸš€ Features
17
+
18
+ - add `binned()` transducer & example ([6e8d9cd](https://github.com/thi-ng/umbrella/commit/6e8d9cd))
19
+
14
20
  ### [9.2.13](https://github.com/thi-ng/umbrella/tree/@thi.ng/transducers@9.2.13) (2025-01-14)
15
21
 
16
22
  #### ♻️ Refactoring
package/README.md CHANGED
@@ -7,7 +7,7 @@
7
7
  [![Mastodon Follow](https://img.shields.io/mastodon/follow/109331703950160316?domain=https%3A%2F%2Fmastodon.thi.ng&style=social)](https://mastodon.thi.ng/@toxi)
8
8
 
9
9
  > [!NOTE]
10
- > This is one of 205 standalone projects, maintained as part
10
+ > This is one of 206 standalone projects, maintained as part
11
11
  > of the [@thi.ng/umbrella](https://github.com/thi-ng/umbrella/) monorepo
12
12
  > and anti-framework.
13
13
  >
@@ -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.12 KB
153
+ Package sizes (brotli'd, pre-treeshake): ESM: 9.16 KB
154
154
 
155
155
  ## Dependencies
156
156
 
@@ -935,6 +935,7 @@ transduce(map((x) => x*10), push(), range(4))
935
935
  ```
936
936
 
937
937
  - [benchmark](https://github.com/thi-ng/umbrella/tree/develop/packages/transducers/src/benchmark.ts)
938
+ - [binned](https://github.com/thi-ng/umbrella/tree/develop/packages/transducers/src/binned.ts)
938
939
  - [cat](https://github.com/thi-ng/umbrella/tree/develop/packages/transducers/src/cat.ts)
939
940
  - [converge](https://github.com/thi-ng/umbrella/tree/develop/packages/transducers/src/converge.ts)
940
941
  - [convolve2d](https://github.com/thi-ng/umbrella/tree/develop/packages/transducers/src/convolve.ts)
package/binned.d.ts ADDED
@@ -0,0 +1,70 @@
1
+ import type { Transducer } from "./api.js";
2
+ /**
3
+ * Config options for {@link binned} transducer
4
+ */
5
+ export interface BinnedOpts {
6
+ /**
7
+ * Rounding precision. Values inside the closed `[min,max]` interval will be
8
+ * rounded to multiples of given `precision.
9
+ *
10
+ * @defaultValue 1
11
+ */
12
+ prec: number;
13
+ /**
14
+ * Lower bounds of interval.
15
+ *
16
+ * @defaultValue -♾️
17
+ */
18
+ min: number;
19
+ /**
20
+ * Upper bounds of interval.
21
+ *
22
+ * @defaultValue +♾️
23
+ */
24
+ max: number;
25
+ }
26
+ /**
27
+ * Transducer to apply binning and interval clipping for numeric values based on
28
+ * provided options. Values in the closed `[min,max]` interval will be rounded
29
+ * to multiples of given `prec`ision (e.g. as a preparation for
30
+ * {@link frequencies} et al). Values outside the interval will be ignored.
31
+ *
32
+ * @example
33
+ * ```ts tangle:../export/binned.ts
34
+ * import { binned, frequencies, pluck, repeatedly, transduce } from "@thi.ng/transducers";
35
+ * import { normal } from "@thi.ng/random";
36
+ * import { barChartVStr } from "@thi.ng/text-canvas";
37
+ *
38
+ * // compute histogram of 1 million gaussian random samples (aka normal distribution)
39
+ * // use binned values and discard those outside configured interval
40
+ * const hist = transduce(
41
+ * binned({ prec: 0.1, min: -3, max: 3 }),
42
+ * frequencies(),
43
+ * repeatedly(normal(), 1e6)
44
+ * );
45
+ * // Map(61) { -3 => 223, ... 0 => 40212, ... 3 => 245 }
46
+ *
47
+ * // sort by key (position)
48
+ * const sorted = [...hist].sort((a,b) => a[0] - b[0]);
49
+ *
50
+ * // draw as ANSI art diagram
51
+ * console.log(barChartVStr(10, pluck(1, sorted)));
52
+ *
53
+ * // β–β–„β–‡β–‡β–ˆβ–†β–†β–„
54
+ * // β–‚β–‡β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–†β–‚
55
+ * // β–β–†β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–†β–
56
+ * // β–…β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–…
57
+ * // β–„β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ƒ
58
+ * // β–‚β–‡β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–‡β–‚
59
+ * // β–β–†β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–†β–
60
+ * // β–‚β–†β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–‡β–ƒ
61
+ * // β–β–‚β–…β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–…β–ƒ
62
+ * // β–β–β–‚β–ƒβ–„β–…β–†β–‡β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–‡β–†β–…β–ƒβ–ƒβ–‚β–β–
63
+ * ```
64
+ *
65
+ * @param opts
66
+ */
67
+ export declare function binned(opts?: Partial<BinnedOpts>): Transducer<number, number>;
68
+ export declare function binned(src: Iterable<number>): IterableIterator<number>;
69
+ export declare function binned(opts: Partial<BinnedOpts>, src: Iterable<number>): IterableIterator<number>;
70
+ //# sourceMappingURL=binned.d.ts.map
package/binned.js ADDED
@@ -0,0 +1,20 @@
1
+ import { roundTo } from "@thi.ng/math/prec";
2
+ import { compR } from "./compr.js";
3
+ import { __iter } from "./iterator.js";
4
+ function binned(...args) {
5
+ return __iter(binned, args) || ((rfn) => {
6
+ const r = rfn[2];
7
+ const {
8
+ prec = 1,
9
+ min = -Infinity,
10
+ max = Infinity
11
+ } = args[0] || {};
12
+ return compR(
13
+ rfn,
14
+ (acc, x) => x < min || x > max ? acc : r(acc, roundTo(x, prec))
15
+ );
16
+ });
17
+ }
18
+ export {
19
+ binned
20
+ };
package/index.d.ts CHANGED
@@ -50,6 +50,7 @@ export * from "./sorted-frequencies.js";
50
50
  export * from "./str.js";
51
51
  export * from "./sub.js";
52
52
  export * from "./benchmark.js";
53
+ export * from "./binned.js";
53
54
  export * from "./cat.js";
54
55
  export * from "./converge.js";
55
56
  export * from "./convolve.js";
package/index.js CHANGED
@@ -50,6 +50,7 @@ export * from "./sorted-frequencies.js";
50
50
  export * from "./str.js";
51
51
  export * from "./sub.js";
52
52
  export * from "./benchmark.js";
53
+ export * from "./binned.js";
53
54
  export * from "./cat.js";
54
55
  export * from "./converge.js";
55
56
  export * from "./convolve.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@thi.ng/transducers",
3
- "version": "9.2.26",
3
+ "version": "9.3.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.26",
47
- "@thi.ng/arrays": "^2.10.23",
48
- "@thi.ng/checks": "^3.7.6",
49
- "@thi.ng/compare": "^2.4.18",
50
- "@thi.ng/compose": "^3.0.29",
51
- "@thi.ng/errors": "^2.5.32",
52
- "@thi.ng/math": "^5.11.26",
53
- "@thi.ng/random": "^4.1.17",
54
- "@thi.ng/timestamp": "^1.1.11"
46
+ "@thi.ng/api": "^8.11.27",
47
+ "@thi.ng/arrays": "^2.11.0",
48
+ "@thi.ng/checks": "^3.7.7",
49
+ "@thi.ng/compare": "^2.4.19",
50
+ "@thi.ng/compose": "^3.0.30",
51
+ "@thi.ng/errors": "^2.5.33",
52
+ "@thi.ng/math": "^5.11.27",
53
+ "@thi.ng/random": "^4.1.18",
54
+ "@thi.ng/timestamp": "^1.1.12"
55
55
  },
56
56
  "devDependencies": {
57
- "esbuild": "^0.25.2",
58
- "typedoc": "^0.28.2",
57
+ "esbuild": "^0.25.3",
58
+ "typedoc": "^0.28.3",
59
59
  "typescript": "^5.8.3"
60
60
  },
61
61
  "keywords": [
@@ -135,6 +135,9 @@
135
135
  "./benchmark": {
136
136
  "default": "./benchmark.js"
137
137
  },
138
+ "./binned": {
139
+ "default": "./binned.js"
140
+ },
138
141
  "./cat": {
139
142
  "default": "./cat.js"
140
143
  },
@@ -603,5 +606,5 @@
603
606
  ],
604
607
  "year": 2016
605
608
  },
606
- "gitHead": "c464b6948f92cba90c2ea75b59203dad894fb450\n"
609
+ "gitHead": "4354686a6fb1f82c09ea48f92f87786191b231a0\n"
607
610
  }