@thi.ng/transducers 9.0.12 → 9.1.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 +8 -1
- package/README.md +6 -3
- package/index.d.ts +2 -0
- package/index.js +2 -0
- package/package.json +23 -15
- package/push-copy.d.ts +7 -0
- package/push-copy.js +1 -1
- package/push-keys.d.ts +25 -0
- package/push-keys.js +10 -0
- package/push.d.ts +4 -1
- package/sorted-frequencies.d.ts +34 -0
- package/sorted-frequencies.js +20 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Change Log
|
|
2
2
|
|
|
3
|
-
- **Last updated**: 2024-
|
|
3
|
+
- **Last updated**: 2024-08-13T19:40:07Z
|
|
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
|
+
## [9.1.0](https://github.com/thi-ng/umbrella/tree/@thi.ng/transducers@9.1.0) (2024-08-13)
|
|
13
|
+
|
|
14
|
+
#### 🚀 Features
|
|
15
|
+
|
|
16
|
+
- add sortedFrequencies() reducer ([1257a79](https://github.com/thi-ng/umbrella/commit/1257a79))
|
|
17
|
+
- add pushKeys() reducer ([f19d152](https://github.com/thi-ng/umbrella/commit/f19d152))
|
|
18
|
+
|
|
12
19
|
### [9.0.6](https://github.com/thi-ng/umbrella/tree/@thi.ng/transducers@9.0.6) (2024-06-21)
|
|
13
20
|
|
|
14
21
|
#### ♻️ Refactoring
|
package/README.md
CHANGED
|
@@ -63,7 +63,7 @@
|
|
|
63
63
|
|
|
64
64
|
## About
|
|
65
65
|
|
|
66
|
-
|
|
66
|
+
Collection of ~170 lightweight, composable transducers, reducers, generators, iterators for functional data transformations.
|
|
67
67
|
|
|
68
68
|
This library provides altogether ~170 transducers, reducers, sequence generators
|
|
69
69
|
(ES6 generators/iterators) and additional supporting functions for composing
|
|
@@ -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: 8.
|
|
153
|
+
Package sizes (brotli'd, pre-treeshake): ESM: 8.97 KB
|
|
154
154
|
|
|
155
155
|
## Dependencies
|
|
156
156
|
|
|
@@ -167,7 +167,7 @@ Note: @thi.ng/api is in _most_ cases a type-only import (not used at runtime)
|
|
|
167
167
|
|
|
168
168
|
## Usage examples
|
|
169
169
|
|
|
170
|
-
|
|
170
|
+
72 projects in this repo's
|
|
171
171
|
[/examples](https://github.com/thi-ng/umbrella/tree/develop/examples)
|
|
172
172
|
directory are using this package:
|
|
173
173
|
|
|
@@ -234,6 +234,7 @@ directory are using this package:
|
|
|
234
234
|
| <img src="https://raw.githubusercontent.com/thi-ng/umbrella/develop/assets/examples/svg-resample.png" width="240"/> | SVG path parsing & dynamic resampling | [Demo](https://demo.thi.ng/umbrella/svg-resample/) | [Source](https://github.com/thi-ng/umbrella/tree/develop/examples/svg-resample) |
|
|
235
235
|
| <img src="https://raw.githubusercontent.com/thi-ng/umbrella/develop/assets/examples/svg-waveform.jpg" width="240"/> | Additive waveform synthesis & SVG visualization with undo/redo | [Demo](https://demo.thi.ng/umbrella/svg-waveform/) | [Source](https://github.com/thi-ng/umbrella/tree/develop/examples/svg-waveform) |
|
|
236
236
|
| <img src="https://raw.githubusercontent.com/thi-ng/umbrella/develop/assets/examples/talk-slides.png" width="240"/> | hdom based slide deck viewer & slides from my ClojureX 2018 keynote | [Demo](http://media.thi.ng/2018/talks/clojurex/index.html) | [Source](https://github.com/thi-ng/umbrella/tree/develop/examples/talk-slides) |
|
|
237
|
+
| <img src="https://raw.githubusercontent.com/thi-ng/umbrella/develop/assets/examples/thing-browser.avif" width="240"/> | Tree-based UI to find & explore thi.ng projects via their associated keywords | [Demo](https://demo.thi.ng/umbrella/thing-browser/) | [Source](https://github.com/thi-ng/umbrella/tree/develop/examples/thing-browser) |
|
|
237
238
|
| <img src="https://raw.githubusercontent.com/thi-ng/umbrella/develop/assets/examples/trace-bitmap.jpg" width="240"/> | Multi-layer vectorization & dithering of bitmap images | [Demo](https://demo.thi.ng/umbrella/trace-bitmap/) | [Source](https://github.com/thi-ng/umbrella/tree/develop/examples/trace-bitmap) |
|
|
238
239
|
| <img src="https://raw.githubusercontent.com/thi-ng/umbrella/develop/assets/examples/triple-query.png" width="240"/> | Triple store query results & sortable table | [Demo](https://demo.thi.ng/umbrella/triple-query/) | [Source](https://github.com/thi-ng/umbrella/tree/develop/examples/triple-query) |
|
|
239
240
|
| <img src="https://raw.githubusercontent.com/thi-ng/umbrella/develop/assets/examples/viz-ridge-lines.avif" width="240"/> | Interactive ridge-line plot | [Demo](https://demo.thi.ng/umbrella/viz-ridge-lines/) | [Source](https://github.com/thi-ng/umbrella/tree/develop/examples/viz-ridge-lines) |
|
|
@@ -1070,9 +1071,11 @@ result (as if it would be called via `reduce()`).
|
|
|
1070
1071
|
- [normFrequenciesAuto](https://github.com/thi-ng/umbrella/tree/develop/packages/transducers/src/norm-frequencies-auto.ts)
|
|
1071
1072
|
- [push](https://github.com/thi-ng/umbrella/tree/develop/packages/transducers/src/push.ts)
|
|
1072
1073
|
- [pushCopy](https://github.com/thi-ng/umbrella/tree/develop/packages/transducers/src/push-copy.ts)
|
|
1074
|
+
- [pushKeys](https://github.com/thi-ng/umbrella/tree/develop/packages/transducers/src/push-keys.ts)
|
|
1073
1075
|
- [pushSort](https://github.com/thi-ng/umbrella/tree/develop/packages/transducers/src/push-sort.ts)
|
|
1074
1076
|
- [reductions](https://github.com/thi-ng/umbrella/tree/develop/packages/transducers/src/reductions.ts)
|
|
1075
1077
|
- [some](https://github.com/thi-ng/umbrella/tree/develop/packages/transducers/src/some.ts)
|
|
1078
|
+
- [sortedFrequencies](https://github.com/thi-ng/umbrella/tree/develop/packages/transducers/src/sorted-frequencies.ts)
|
|
1076
1079
|
- [str](https://github.com/thi-ng/umbrella/tree/develop/packages/transducers/src/str.ts)
|
|
1077
1080
|
- [sub](https://github.com/thi-ng/umbrella/tree/develop/packages/transducers/src/sub.ts)
|
|
1078
1081
|
|
package/index.d.ts
CHANGED
|
@@ -42,9 +42,11 @@ export * from "./norm-frequencies.js";
|
|
|
42
42
|
export * from "./norm-frequencies-auto.js";
|
|
43
43
|
export * from "./push.js";
|
|
44
44
|
export * from "./push-copy.js";
|
|
45
|
+
export * from "./push-keys.js";
|
|
45
46
|
export * from "./push-sort.js";
|
|
46
47
|
export * from "./reductions.js";
|
|
47
48
|
export * from "./some.js";
|
|
49
|
+
export * from "./sorted-frequencies.js";
|
|
48
50
|
export * from "./str.js";
|
|
49
51
|
export * from "./sub.js";
|
|
50
52
|
export * from "./benchmark.js";
|
package/index.js
CHANGED
|
@@ -42,9 +42,11 @@ export * from "./norm-frequencies.js";
|
|
|
42
42
|
export * from "./norm-frequencies-auto.js";
|
|
43
43
|
export * from "./push.js";
|
|
44
44
|
export * from "./push-copy.js";
|
|
45
|
+
export * from "./push-keys.js";
|
|
45
46
|
export * from "./push-sort.js";
|
|
46
47
|
export * from "./reductions.js";
|
|
47
48
|
export * from "./some.js";
|
|
49
|
+
export * from "./sorted-frequencies.js";
|
|
48
50
|
export * from "./str.js";
|
|
49
51
|
export * from "./sub.js";
|
|
50
52
|
export * from "./benchmark.js";
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@thi.ng/transducers",
|
|
3
|
-
"version": "9.0
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "9.1.0",
|
|
4
|
+
"description": "Collection of ~170 lightweight, composable transducers, reducers, generators, iterators for functional data transformations",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"module": "./index.js",
|
|
7
7
|
"typings": "./index.d.ts",
|
|
@@ -40,22 +40,23 @@
|
|
|
40
40
|
"tool:tangle": "../../node_modules/.bin/tangle src/**/*.ts"
|
|
41
41
|
},
|
|
42
42
|
"dependencies": {
|
|
43
|
-
"@thi.ng/api": "^8.11.
|
|
44
|
-
"@thi.ng/arrays": "^2.9.
|
|
45
|
-
"@thi.ng/checks": "^3.6.
|
|
46
|
-
"@thi.ng/compare": "^2.
|
|
47
|
-
"@thi.ng/compose": "^3.0.
|
|
48
|
-
"@thi.ng/errors": "^2.5.
|
|
49
|
-
"@thi.ng/math": "^5.11.
|
|
50
|
-
"@thi.ng/random": "^4.0.
|
|
43
|
+
"@thi.ng/api": "^8.11.8",
|
|
44
|
+
"@thi.ng/arrays": "^2.9.14",
|
|
45
|
+
"@thi.ng/checks": "^3.6.10",
|
|
46
|
+
"@thi.ng/compare": "^2.4.0",
|
|
47
|
+
"@thi.ng/compose": "^3.0.11",
|
|
48
|
+
"@thi.ng/errors": "^2.5.14",
|
|
49
|
+
"@thi.ng/math": "^5.11.7",
|
|
50
|
+
"@thi.ng/random": "^4.0.2"
|
|
51
51
|
},
|
|
52
52
|
"devDependencies": {
|
|
53
|
-
"@microsoft/api-extractor": "^7.47.
|
|
53
|
+
"@microsoft/api-extractor": "^7.47.5",
|
|
54
54
|
"esbuild": "^0.23.0",
|
|
55
|
-
"typedoc": "^0.26.
|
|
56
|
-
"typescript": "^5.5.
|
|
55
|
+
"typedoc": "^0.26.5",
|
|
56
|
+
"typescript": "^5.5.4"
|
|
57
57
|
},
|
|
58
58
|
"keywords": [
|
|
59
|
+
"1d",
|
|
59
60
|
"2d",
|
|
60
61
|
"3d",
|
|
61
62
|
"array",
|
|
@@ -69,11 +70,12 @@
|
|
|
69
70
|
"functional",
|
|
70
71
|
"fuzzy",
|
|
71
72
|
"generator",
|
|
72
|
-
"group
|
|
73
|
+
"group",
|
|
73
74
|
"histogram",
|
|
74
75
|
"interleave",
|
|
75
76
|
"interpolation",
|
|
76
77
|
"iterator",
|
|
78
|
+
"kernel",
|
|
77
79
|
"nd",
|
|
78
80
|
"partition",
|
|
79
81
|
"permutation",
|
|
@@ -420,6 +422,9 @@
|
|
|
420
422
|
"./push-copy": {
|
|
421
423
|
"default": "./push-copy.js"
|
|
422
424
|
},
|
|
425
|
+
"./push-keys": {
|
|
426
|
+
"default": "./push-keys.js"
|
|
427
|
+
},
|
|
423
428
|
"./push-sort": {
|
|
424
429
|
"default": "./push-sort.js"
|
|
425
430
|
},
|
|
@@ -492,6 +497,9 @@
|
|
|
492
497
|
"./some": {
|
|
493
498
|
"default": "./some.js"
|
|
494
499
|
},
|
|
500
|
+
"./sorted-frequencies": {
|
|
501
|
+
"default": "./sorted-frequencies.js"
|
|
502
|
+
},
|
|
495
503
|
"./sorted-keys": {
|
|
496
504
|
"default": "./sorted-keys.js"
|
|
497
505
|
},
|
|
@@ -588,5 +596,5 @@
|
|
|
588
596
|
],
|
|
589
597
|
"year": 2016
|
|
590
598
|
},
|
|
591
|
-
"gitHead": "
|
|
599
|
+
"gitHead": "e914ebbd81c56783c39cf746548c547cbacadc96\n"
|
|
592
600
|
}
|
package/push-copy.d.ts
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
1
|
import type { Reducer } from "./api.js";
|
|
2
|
+
/**
|
|
3
|
+
* Reducer. Special version of {@link push}, which immutably appends inputs to
|
|
4
|
+
* an array, yielding a new array for each reduction step.
|
|
5
|
+
*
|
|
6
|
+
* @remarks
|
|
7
|
+
* Also see {@link pushKeys}, {@link pushSort}.
|
|
8
|
+
*/
|
|
2
9
|
export declare const pushCopy: <T>() => Reducer<T, T[]>;
|
|
3
10
|
//# sourceMappingURL=push-copy.d.ts.map
|
package/push-copy.js
CHANGED
package/push-keys.d.ts
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { Keys } from "@thi.ng/api";
|
|
2
|
+
import type { Reducer } from "./api.js";
|
|
3
|
+
/**
|
|
4
|
+
* Reducer. Combination of {@link push} and {@link pluck}, which looks up given
|
|
5
|
+
* `key` in each input and collects these values into an array.
|
|
6
|
+
*
|
|
7
|
+
* @remarks
|
|
8
|
+
* Also see {@link pushCopy}, {@link pushSort}.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```ts tangle:../export/push-keys.ts
|
|
12
|
+
* import { pushKeys } from "@thi.ng/transducers";
|
|
13
|
+
*
|
|
14
|
+
* const data = [{id: "a", val: 1}, {id: "b", val: 2}, {id: "c", val: 3}];
|
|
15
|
+
*
|
|
16
|
+
* console.log(pushKeys("id", data));
|
|
17
|
+
* // ["a", "b", "c"]
|
|
18
|
+
*
|
|
19
|
+
* console.log(pushKeys("val", data));
|
|
20
|
+
* // [1, 2, 3]
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
export declare function pushKeys<T, K extends Keys<T>>(key: K): Reducer<T, T[K][]>;
|
|
24
|
+
export declare function pushKeys<T, K extends Keys<T>>(key: K, src: Iterable<T>): T[K][];
|
|
25
|
+
//# sourceMappingURL=push-keys.d.ts.map
|
package/push-keys.js
ADDED
package/push.d.ts
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import type { Reducer } from "./api.js";
|
|
2
2
|
/**
|
|
3
|
-
* Reducer which collects inputs into
|
|
3
|
+
* Reducer which collects inputs into an array.
|
|
4
|
+
*
|
|
5
|
+
* @remarks
|
|
6
|
+
* Also see {@link pushCopy}, {@link pushKeys}, {@link pushSort}.
|
|
4
7
|
*/
|
|
5
8
|
export declare function push<T>(): Reducer<T, T[]>;
|
|
6
9
|
export declare function push<T>(src: Iterable<T>): T[];
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { Fn } from "@thi.ng/api";
|
|
2
|
+
import type { Reducer } from "./api.js";
|
|
3
|
+
/**
|
|
4
|
+
* Reducer. Similar to {@link frequencies}, but instead of a Map produces an
|
|
5
|
+
* array of `[value, frequency]`-pairs, sorted by the descending number of
|
|
6
|
+
* occurrences of each distinct value.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```ts tangle:../export/sorted-frequencies.ts
|
|
10
|
+
* import { filter, sortedFrequencies, transduce } from "@thi.ng/transducers";
|
|
11
|
+
*
|
|
12
|
+
* const input = "hello, world! this transducers-stuff is pretty awesome! :)";
|
|
13
|
+
*
|
|
14
|
+
* const freqs = transduce(
|
|
15
|
+
* filter(x => /[a-z0-9]/.test(x)),
|
|
16
|
+
* sortedFrequencies(),
|
|
17
|
+
* input
|
|
18
|
+
* );
|
|
19
|
+
*
|
|
20
|
+
* console.log(freqs);
|
|
21
|
+
* // [
|
|
22
|
+
* // [ 's', 6 ], [ 'e', 5 ], [ 't', 5 ], [ 'r', 4 ],
|
|
23
|
+
* // [ 'l', 3 ], [ 'o', 3 ], [ 'h', 2 ], [ 'w', 2 ],
|
|
24
|
+
* // [ 'd', 2 ], [ 'i', 2 ], [ 'a', 2 ], [ 'u', 2 ],
|
|
25
|
+
* // [ 'f', 2 ], [ 'n', 1 ], [ 'c', 1 ], [ 'p', 1 ],
|
|
26
|
+
* // [ 'y', 1 ], [ 'm', 1 ]
|
|
27
|
+
* // ]
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
export declare function sortedFrequencies<A>(): Reducer<A, [A, number][]>;
|
|
31
|
+
export declare function sortedFrequencies<A>(src: Iterable<A>): [A, number][];
|
|
32
|
+
export declare function sortedFrequencies<A, B>(key: Fn<A, B>): Reducer<A, [B, number][]>;
|
|
33
|
+
export declare function sortedFrequencies<A, B>(key: Fn<A, B>, src: Iterable<A>): Map<B, number>;
|
|
34
|
+
//# sourceMappingURL=sorted-frequencies.d.ts.map
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { identity } from "@thi.ng/compose/identity";
|
|
2
|
+
import { count } from "./count.js";
|
|
3
|
+
import { groupByMap } from "./group-by-map.js";
|
|
4
|
+
import { $$reduce } from "./reduce.js";
|
|
5
|
+
function sortedFrequencies(...args) {
|
|
6
|
+
const res = $$reduce(sortedFrequencies, args);
|
|
7
|
+
if (res) return res;
|
|
8
|
+
const [init, complete, reduce] = groupByMap({
|
|
9
|
+
key: args[0] || identity,
|
|
10
|
+
group: count()
|
|
11
|
+
});
|
|
12
|
+
return [
|
|
13
|
+
init,
|
|
14
|
+
(acc) => [...complete(acc)].sort((a, b) => b[1] - a[1]),
|
|
15
|
+
(acc, x) => reduce(acc, x)
|
|
16
|
+
];
|
|
17
|
+
}
|
|
18
|
+
export {
|
|
19
|
+
sortedFrequencies
|
|
20
|
+
};
|