@thi.ng/transducers-async 0.2.5 → 0.2.7
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 +10 -1
- package/README.md +1 -1
- package/concat.d.ts +2 -2
- package/concat.js +3 -3
- package/internal/iter.d.ts +21 -0
- package/internal/iter.js +15 -0
- package/iterator.d.ts +2 -2
- package/iterator.js +4 -4
- package/merge.js +4 -11
- package/package.json +14 -13
- package/push.d.ts +1 -1
- package/push.js +3 -3
- package/reduce.js +3 -3
- package/sync.js +7 -13
- package/transduce.js +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Change Log
|
|
2
2
|
|
|
3
|
-
- **Last updated**: 2024-
|
|
3
|
+
- **Last updated**: 2024-06-29T09:28:36Z
|
|
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,15 @@ 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
|
+
### [0.2.6](https://github.com/thi-ng/umbrella/tree/@thi.ng/transducers-async@0.2.6) (2024-06-21)
|
|
13
|
+
|
|
14
|
+
#### ♻️ Refactoring
|
|
15
|
+
|
|
16
|
+
- rename various rest args to be more semantically meaningful ([8088a56](https://github.com/thi-ng/umbrella/commit/8088a56))
|
|
17
|
+
- update merge()/sync() ([ef82528](https://github.com/thi-ng/umbrella/commit/ef82528))
|
|
18
|
+
- dedupe internal shared functionality
|
|
19
|
+
- dedupe iter removal in merge()/sync() ([abc6a46](https://github.com/thi-ng/umbrella/commit/abc6a46))
|
|
20
|
+
|
|
12
21
|
## [0.2.0](https://github.com/thi-ng/umbrella/tree/@thi.ng/transducers-async@0.2.0) (2024-04-20)
|
|
13
22
|
|
|
14
23
|
#### 🚀 Features
|
package/README.md
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
[](https://mastodon.thi.ng/@toxi)
|
|
8
8
|
|
|
9
9
|
> [!NOTE]
|
|
10
|
-
> This is one of
|
|
10
|
+
> This is one of 189 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
|
>
|
package/concat.d.ts
CHANGED
|
@@ -27,7 +27,7 @@ import type { MaybeAsyncIterable, Nullable } from "@thi.ng/api";
|
|
|
27
27
|
* // [ 1, 2, 3, undefined, 4, 5 ]
|
|
28
28
|
* ```
|
|
29
29
|
*
|
|
30
|
-
* @param
|
|
30
|
+
* @param sources -
|
|
31
31
|
*/
|
|
32
|
-
export declare function concat<T>(...
|
|
32
|
+
export declare function concat<T>(...sources: Nullable<MaybeAsyncIterable<T>>[]): AsyncIterableIterator<T>;
|
|
33
33
|
//# sourceMappingURL=concat.d.ts.map
|
package/concat.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ensureIterable } from "./ensure.js";
|
|
2
|
-
async function* concat(...
|
|
3
|
-
for (let
|
|
4
|
-
|
|
2
|
+
async function* concat(...sources) {
|
|
3
|
+
for (let src of sources) {
|
|
4
|
+
src != null && (yield* ensureIterable(src));
|
|
5
5
|
}
|
|
6
6
|
}
|
|
7
7
|
export {
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/** @internal */
|
|
2
|
+
export declare const __inflightIters: <T extends {
|
|
3
|
+
iter: AsyncIterator<any>;
|
|
4
|
+
}>(iters: T[]) => Promise<{
|
|
5
|
+
iter: T;
|
|
6
|
+
res: IteratorResult<any, any>;
|
|
7
|
+
}>[];
|
|
8
|
+
/** @internal */
|
|
9
|
+
export declare const __iterNext: <T extends {
|
|
10
|
+
id: number;
|
|
11
|
+
iter: AsyncIterator<any>;
|
|
12
|
+
}>(promises: Promise<{
|
|
13
|
+
iter: T;
|
|
14
|
+
res: IteratorResult<any, any>;
|
|
15
|
+
}>[], iter: T) => void;
|
|
16
|
+
/** @internal */
|
|
17
|
+
export declare const __iterRemove: <T extends {
|
|
18
|
+
id: number;
|
|
19
|
+
iter: AsyncIterator<any>;
|
|
20
|
+
}>(iters: T[], id: number) => true | undefined;
|
|
21
|
+
//# sourceMappingURL=iter.d.ts.map
|
package/internal/iter.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
const __inflightIters = (iters) => iters.map((iter) => iter.iter.next().then((res) => ({ iter, res })));
|
|
2
|
+
const __iterNext = (promises, iter) => {
|
|
3
|
+
promises[iter.id] = iter.iter.next().then((res) => ({ res, iter }));
|
|
4
|
+
};
|
|
5
|
+
const __iterRemove = (iters, id) => {
|
|
6
|
+
iters.splice(id, 1);
|
|
7
|
+
const n = iters.length;
|
|
8
|
+
if (!n) return true;
|
|
9
|
+
for (let i = id; i < n; i++) iters[i].id--;
|
|
10
|
+
};
|
|
11
|
+
export {
|
|
12
|
+
__inflightIters,
|
|
13
|
+
__iterNext,
|
|
14
|
+
__iterRemove
|
|
15
|
+
};
|
package/iterator.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { FnAny, MaybeAsyncIterable } from "@thi.ng/api";
|
|
2
2
|
import type { AsyncTransducer, AsyncTxLike } from "./api.js";
|
|
3
|
-
export declare function iterator1<A, B>(xform: AsyncTxLike<A, B>,
|
|
4
|
-
export declare function iterator<A, B>(xform: AsyncTxLike<A, B>,
|
|
3
|
+
export declare function iterator1<A, B>(xform: AsyncTxLike<A, B>, src: MaybeAsyncIterable<A>): AsyncIterableIterator<B>;
|
|
4
|
+
export declare function iterator<A, B>(xform: AsyncTxLike<A, B>, src: MaybeAsyncIterable<A>): AsyncIterableIterator<B>;
|
|
5
5
|
export declare const __iter: (xform: FnAny<AsyncTransducer<any, any>>, args: any[], impl?: typeof iterator1) => AsyncIterableIterator<any> | undefined;
|
|
6
6
|
//# sourceMappingURL=iterator.d.ts.map
|
package/iterator.js
CHANGED
|
@@ -4,9 +4,9 @@ import { isIterable } from "@thi.ng/checks/is-iterable";
|
|
|
4
4
|
import { isReduced } from "@thi.ng/transducers/reduced";
|
|
5
5
|
import { ensureAsyncTransducer } from "./ensure.js";
|
|
6
6
|
import { push } from "./push.js";
|
|
7
|
-
async function* iterator1(xform,
|
|
7
|
+
async function* iterator1(xform, src) {
|
|
8
8
|
const [_, complete, reduce] = ensureAsyncTransducer(xform)([NO_OP, NO_OP, (_2, x) => x]);
|
|
9
|
-
for await (let x of
|
|
9
|
+
for await (let x of src) {
|
|
10
10
|
let y = await reduce(SEMAPHORE, x);
|
|
11
11
|
if (isReduced(y)) {
|
|
12
12
|
const res = await complete(y.deref());
|
|
@@ -20,11 +20,11 @@ async function* iterator1(xform, xs) {
|
|
|
20
20
|
}
|
|
21
21
|
}
|
|
22
22
|
}
|
|
23
|
-
async function* iterator(xform,
|
|
23
|
+
async function* iterator(xform, src) {
|
|
24
24
|
const [_, complete, reduce] = ensureAsyncTransducer(
|
|
25
25
|
xform
|
|
26
26
|
)(push());
|
|
27
|
-
for await (let x of
|
|
27
|
+
for await (let x of src) {
|
|
28
28
|
const y = await reduce([], x);
|
|
29
29
|
if (isReduced(y)) {
|
|
30
30
|
yield* await complete(y.deref());
|
package/merge.js
CHANGED
|
@@ -1,22 +1,15 @@
|
|
|
1
|
+
import { __inflightIters, __iterNext, __iterRemove } from "./internal/iter.js";
|
|
1
2
|
async function* merge(src) {
|
|
2
3
|
const iters = src.map((v, id) => ({ id, iter: v[Symbol.asyncIterator]() }));
|
|
3
|
-
|
|
4
|
-
const $remove = (id) => {
|
|
5
|
-
iters.splice(id, 1);
|
|
6
|
-
if (!--n) return true;
|
|
7
|
-
for (let i = id; i < n; i++) iters[i].id--;
|
|
8
|
-
};
|
|
9
|
-
const promises = iters.map(
|
|
10
|
-
(iter) => iter.iter.next().then((res) => ({ iter, res }))
|
|
11
|
-
);
|
|
4
|
+
const promises = __inflightIters(iters);
|
|
12
5
|
while (true) {
|
|
13
6
|
const { iter, res } = await Promise.race(promises);
|
|
14
7
|
if (res.done) {
|
|
15
8
|
promises.splice(iter.id, 1);
|
|
16
|
-
if (
|
|
9
|
+
if (__iterRemove(iters, iter.id)) return;
|
|
17
10
|
} else {
|
|
18
11
|
yield res.value;
|
|
19
|
-
promises
|
|
12
|
+
__iterNext(promises, iter);
|
|
20
13
|
}
|
|
21
14
|
}
|
|
22
15
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@thi.ng/transducers-async",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.7",
|
|
4
4
|
"description": "Async versions of various highly composable transducers, reducers and iterators",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"module": "./index.js",
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
"type": "git",
|
|
11
11
|
"url": "https://github.com/thi-ng/umbrella.git"
|
|
12
12
|
},
|
|
13
|
-
"homepage": "https://
|
|
13
|
+
"homepage": "https://thi.ng/transducers-async",
|
|
14
14
|
"funding": [
|
|
15
15
|
{
|
|
16
16
|
"type": "github",
|
|
@@ -36,18 +36,18 @@
|
|
|
36
36
|
"tool:tangle": "../../node_modules/.bin/tangle src/**/*.ts"
|
|
37
37
|
},
|
|
38
38
|
"dependencies": {
|
|
39
|
-
"@thi.ng/api": "^8.11.
|
|
40
|
-
"@thi.ng/buffers": "^0.1.
|
|
41
|
-
"@thi.ng/checks": "^3.6.
|
|
42
|
-
"@thi.ng/compose": "^3.0.
|
|
43
|
-
"@thi.ng/errors": "^2.5.
|
|
44
|
-
"@thi.ng/transducers": "^9.0.
|
|
39
|
+
"@thi.ng/api": "^8.11.4",
|
|
40
|
+
"@thi.ng/buffers": "^0.1.5",
|
|
41
|
+
"@thi.ng/checks": "^3.6.6",
|
|
42
|
+
"@thi.ng/compose": "^3.0.6",
|
|
43
|
+
"@thi.ng/errors": "^2.5.9",
|
|
44
|
+
"@thi.ng/transducers": "^9.0.7"
|
|
45
45
|
},
|
|
46
46
|
"devDependencies": {
|
|
47
|
-
"@microsoft/api-extractor": "^7.
|
|
48
|
-
"esbuild": "^0.21.
|
|
47
|
+
"@microsoft/api-extractor": "^7.47.0",
|
|
48
|
+
"esbuild": "^0.21.5",
|
|
49
49
|
"typedoc": "^0.25.13",
|
|
50
|
-
"typescript": "^5.
|
|
50
|
+
"typescript": "^5.5.2"
|
|
51
51
|
},
|
|
52
52
|
"keywords": [
|
|
53
53
|
"async",
|
|
@@ -81,7 +81,8 @@
|
|
|
81
81
|
},
|
|
82
82
|
"files": [
|
|
83
83
|
"./*.js",
|
|
84
|
-
"./*.d.ts"
|
|
84
|
+
"./*.d.ts",
|
|
85
|
+
"internal"
|
|
85
86
|
],
|
|
86
87
|
"exports": {
|
|
87
88
|
".": {
|
|
@@ -204,5 +205,5 @@
|
|
|
204
205
|
"status": "alpha",
|
|
205
206
|
"year": 2018
|
|
206
207
|
},
|
|
207
|
-
"gitHead": "
|
|
208
|
+
"gitHead": "7b950c112fba0b2e7c450765b15624c3382f1354\n"
|
|
208
209
|
}
|
package/push.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { MaybeAsyncIterable } from "@thi.ng/api";
|
|
2
2
|
import type { AsyncReducer } from "./api.js";
|
|
3
3
|
export declare function push<T>(): AsyncReducer<T, T[]>;
|
|
4
|
-
export declare function push<T>(
|
|
4
|
+
export declare function push<T>(src: MaybeAsyncIterable<T>): Promise<T[]>;
|
|
5
5
|
//# sourceMappingURL=push.d.ts.map
|
package/push.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { reducer } from "./reduce.js";
|
|
2
|
-
function push(
|
|
3
|
-
return
|
|
2
|
+
function push(src) {
|
|
3
|
+
return src ? (async () => {
|
|
4
4
|
let res = [];
|
|
5
|
-
for await (let x of
|
|
5
|
+
for await (let x of src) res.push(x);
|
|
6
6
|
return res;
|
|
7
7
|
})() : reducer(
|
|
8
8
|
() => [],
|
package/reduce.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { asyncIdentity } from "@thi.ng/api/async";
|
|
2
2
|
import { isReduced } from "@thi.ng/transducers/reduced";
|
|
3
|
-
async function reduce([init, complete, $reduce], ...
|
|
4
|
-
let acc =
|
|
5
|
-
for await (let x of
|
|
3
|
+
async function reduce([init, complete, $reduce], ...args) {
|
|
4
|
+
let acc = args.length < 2 ? await init() : args.shift();
|
|
5
|
+
for await (let x of args[0]) {
|
|
6
6
|
const y = await $reduce(acc, x);
|
|
7
7
|
if (isReduced(y)) {
|
|
8
8
|
acc = y.deref();
|
package/sync.js
CHANGED
|
@@ -1,21 +1,17 @@
|
|
|
1
|
+
import { __inflightIters, __iterNext, __iterRemove } from "./internal/iter.js";
|
|
1
2
|
async function* sync(src, opts) {
|
|
2
3
|
let iters = Object.entries(src).map(([key, v], id) => ({
|
|
3
4
|
key,
|
|
4
5
|
id,
|
|
5
6
|
iter: v[Symbol.asyncIterator]()
|
|
6
7
|
}));
|
|
7
|
-
let n = iters.length;
|
|
8
|
-
const $remove = (id) => {
|
|
9
|
-
iters.splice(id, 1);
|
|
10
|
-
if (!--n) return true;
|
|
11
|
-
for (let i = id; i < n; i++) iters[i].id--;
|
|
12
|
-
};
|
|
13
8
|
const $initial = async () => {
|
|
14
9
|
const res = await Promise.all(iters.map(({ iter }) => iter.next()));
|
|
15
|
-
for (let i = 0; i < n; ) {
|
|
10
|
+
for (let i = 0, n = iters.length; i < n; ) {
|
|
16
11
|
if (res[i].done) {
|
|
17
12
|
res.splice(i, 1);
|
|
18
|
-
if (
|
|
13
|
+
if (__iterRemove(iters, i)) return;
|
|
14
|
+
n--;
|
|
19
15
|
} else i++;
|
|
20
16
|
}
|
|
21
17
|
return res.reduce(
|
|
@@ -39,18 +35,16 @@ async function* sync(src, opts) {
|
|
|
39
35
|
if (!tuple) return;
|
|
40
36
|
yield { ...tuple };
|
|
41
37
|
}
|
|
42
|
-
const promises = iters
|
|
43
|
-
(iter) => iter.iter.next().then((res) => ({ iter, res }))
|
|
44
|
-
);
|
|
38
|
+
const promises = __inflightIters(iters);
|
|
45
39
|
while (true) {
|
|
46
40
|
const { iter, res } = await Promise.race(promises);
|
|
47
41
|
if (res.done) {
|
|
48
42
|
promises.splice(iter.id, 1);
|
|
49
|
-
if (
|
|
43
|
+
if (__iterRemove(iters, iter.id)) return;
|
|
50
44
|
} else {
|
|
51
45
|
tuple[iter.key] = res.value;
|
|
52
46
|
yield { ...tuple };
|
|
53
|
-
promises
|
|
47
|
+
__iterNext(promises, iter);
|
|
54
48
|
}
|
|
55
49
|
}
|
|
56
50
|
}
|
package/transduce.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ensureAsyncTransducer } from "./ensure.js";
|
|
2
2
|
import { reduce } from "./reduce.js";
|
|
3
|
-
function transduce(xform, reducer, ...
|
|
4
|
-
return reduce(ensureAsyncTransducer(xform)(reducer), ...
|
|
3
|
+
function transduce(xform, reducer, ...args) {
|
|
4
|
+
return reduce(ensureAsyncTransducer(xform)(reducer), ...args);
|
|
5
5
|
}
|
|
6
6
|
export {
|
|
7
7
|
transduce
|