@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 CHANGED
@@ -1,6 +1,6 @@
1
1
  # Change Log
2
2
 
3
- - **Last updated**: 2024-05-08T18:24:31Z
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
  [![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 192 standalone projects, maintained as part
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 xs -
30
+ * @param sources -
31
31
  */
32
- export declare function concat<T>(...xs: Nullable<MaybeAsyncIterable<T>>[]): AsyncIterableIterator<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(...xs) {
3
- for (let x of xs) {
4
- x != null && (yield* ensureIterable(x));
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
@@ -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>, xs: MaybeAsyncIterable<A>): AsyncIterableIterator<B>;
4
- export declare function iterator<A, B>(xform: AsyncTxLike<A, B>, xs: MaybeAsyncIterable<A>): AsyncIterableIterator<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, xs) {
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 xs) {
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, xs) {
23
+ async function* iterator(xform, src) {
24
24
  const [_, complete, reduce] = ensureAsyncTransducer(
25
25
  xform
26
26
  )(push());
27
- for await (let x of xs) {
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
- let n = iters.length;
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 ($remove(iter.id)) return;
9
+ if (__iterRemove(iters, iter.id)) return;
17
10
  } else {
18
11
  yield res.value;
19
- promises[iter.id] = iter.iter.next().then((res2) => ({ res: res2, iter }));
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.5",
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://github.com/thi-ng/umbrella/tree/develop/packages/transducers-async#readme",
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.2",
40
- "@thi.ng/buffers": "^0.1.3",
41
- "@thi.ng/checks": "^3.6.4",
42
- "@thi.ng/compose": "^3.0.4",
43
- "@thi.ng/errors": "^2.5.7",
44
- "@thi.ng/transducers": "^9.0.5"
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.43.2",
48
- "esbuild": "^0.21.1",
47
+ "@microsoft/api-extractor": "^7.47.0",
48
+ "esbuild": "^0.21.5",
49
49
  "typedoc": "^0.25.13",
50
- "typescript": "^5.4.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": "df34b4a9e650cc7323575356de207d78933bdcf3\n"
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>(xs: MaybeAsyncIterable<T>): Promise<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(xs) {
3
- return xs ? (async () => {
2
+ function push(src) {
3
+ return src ? (async () => {
4
4
  let res = [];
5
- for await (let x of xs) res.push(x);
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], ...xs) {
4
- let acc = xs.length < 2 ? await init() : xs.shift();
5
- for await (let x of xs[0]) {
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 ($remove(i)) return;
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.map(
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 ($remove(iter.id)) return;
43
+ if (__iterRemove(iters, iter.id)) return;
50
44
  } else {
51
45
  tuple[iter.key] = res.value;
52
46
  yield { ...tuple };
53
- promises[iter.id] = iter.iter.next().then((res2) => ({ res: res2, iter }));
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, ...xs) {
4
- return reduce(ensureAsyncTransducer(xform)(reducer), ...xs);
3
+ function transduce(xform, reducer, ...args) {
4
+ return reduce(ensureAsyncTransducer(xform)(reducer), ...args);
5
5
  }
6
6
  export {
7
7
  transduce