spliterator 5.0.0 → 6.0.1

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.
Files changed (61) hide show
  1. package/README.md +56 -0
  2. package/out/index.d.ts +7 -1
  3. package/out/index.d.ts.map +1 -1
  4. package/out/index.js +7 -1
  5. package/out/index.js.map +1 -1
  6. package/out/lib/AsyncSequence.d.ts +180 -0
  7. package/out/lib/AsyncSequence.d.ts.map +1 -0
  8. package/out/lib/AsyncSequence.js +432 -0
  9. package/out/lib/AsyncSequence.js.map +1 -0
  10. package/out/lib/AsyncSpliterator.d.ts +4 -2
  11. package/out/lib/AsyncSpliterator.d.ts.map +1 -1
  12. package/out/lib/AsyncSpliterator.js.map +1 -1
  13. package/out/lib/CSVSpliterator.d.ts +6 -5
  14. package/out/lib/CSVSpliterator.d.ts.map +1 -1
  15. package/out/lib/CSVSpliterator.js +46 -37
  16. package/out/lib/CSVSpliterator.js.map +1 -1
  17. package/out/lib/JSONSpliterator.d.ts +23 -11
  18. package/out/lib/JSONSpliterator.d.ts.map +1 -1
  19. package/out/lib/JSONSpliterator.js +28 -19
  20. package/out/lib/JSONSpliterator.js.map +1 -1
  21. package/out/lib/TextSpliterator.d.ts +4 -2
  22. package/out/lib/TextSpliterator.d.ts.map +1 -1
  23. package/out/lib/TextSpliterator.js +8 -9
  24. package/out/lib/TextSpliterator.js.map +1 -1
  25. package/out/lib/adaptive-source.d.ts +39 -0
  26. package/out/lib/adaptive-source.d.ts.map +1 -0
  27. package/out/lib/adaptive-source.js +95 -0
  28. package/out/lib/adaptive-source.js.map +1 -0
  29. package/out/lib/chunks.d.ts +20 -0
  30. package/out/lib/chunks.d.ts.map +1 -0
  31. package/out/lib/chunks.js +36 -0
  32. package/out/lib/chunks.js.map +1 -0
  33. package/out/lib/parallel-map-workers.d.ts +57 -0
  34. package/out/lib/parallel-map-workers.d.ts.map +1 -0
  35. package/out/lib/parallel-map-workers.js +82 -0
  36. package/out/lib/parallel-map-workers.js.map +1 -0
  37. package/out/lib/parallel-map.d.ts +17 -42
  38. package/out/lib/parallel-map.d.ts.map +1 -1
  39. package/out/lib/parallel-map.js +18 -66
  40. package/out/lib/parallel-map.js.map +1 -1
  41. package/out/lib/pivot.d.ts +30 -0
  42. package/out/lib/pivot.d.ts.map +1 -0
  43. package/out/lib/pivot.js +47 -0
  44. package/out/lib/pivot.js.map +1 -0
  45. package/out/lib/shared.d.ts +0 -27
  46. package/out/lib/shared.d.ts.map +1 -1
  47. package/out/lib/shared.js +0 -53
  48. package/out/lib/shared.js.map +1 -1
  49. package/out/lib/take.d.ts +16 -0
  50. package/out/lib/take.d.ts.map +1 -1
  51. package/out/lib/take.js +28 -0
  52. package/out/lib/take.js.map +1 -1
  53. package/out/lib/utils.d.ts +37 -0
  54. package/out/lib/utils.d.ts.map +1 -0
  55. package/out/lib/utils.js +39 -0
  56. package/out/lib/utils.js.map +1 -0
  57. package/out/lib/zip.d.ts +33 -0
  58. package/out/lib/zip.d.ts.map +1 -0
  59. package/out/lib/zip.js +59 -0
  60. package/out/lib/zip.js.map +1 -0
  61. package/package.json +6 -6
@@ -0,0 +1,57 @@
1
+ /**
2
+ * @copyright Sister Software
3
+ * @license MIT
4
+ * @author Teffen Ellis, et al.
5
+ */
6
+ /**
7
+ * Per-item handler a parallelMapWorkers worker module exports. `index` is per-worker monotonic.
8
+ */
9
+ export type ParallelHandler<T = unknown, R = unknown> = (item: T, ctx: {
10
+ index: number;
11
+ }) => R | Uint8Array | undefined | Promise<R | Uint8Array | undefined>;
12
+ export interface ParallelMapWorkersOptions {
13
+ /**
14
+ * Worker module path/URL exporting `handleItem(item, ctx)`. Top-level code = per-worker init.
15
+ */
16
+ worker: string | URL;
17
+ /**
18
+ * Number of worker threads in the pool. Keep it SMALL for I/O- or memory-bound handlers (per-row DB lookups, large
19
+ * shared datasets): throughput typically peaks at ~2–3 and _degrades_ past that as workers contend for the shared
20
+ * resource — only CPU-bound handlers scale toward the core count. Also bounded by RAM (each worker re-inits its
21
+ * deps). Sweep it for your workload rather than defaulting to `availableParallelism()`.
22
+ */
23
+ concurrency: number;
24
+ /**
25
+ * Items per dispatched batch. @default 64
26
+ */
27
+ batchSize?: number;
28
+ /**
29
+ * Forwarded to every worker via `workerData.userData` (must be structured-cloneable).
30
+ */
31
+ workerData?: unknown;
32
+ }
33
+ /**
34
+ * Map an async (or sync) iterable through a pool of worker threads. Main pulls items from `source`, batches them, and
35
+ * dispatches each batch to an idle worker running the `worker` handler module; results stream back as a single merged
36
+ * async iterator in **completion order** (not input order). A handler returning `undefined` drops that item; a
37
+ * `Uint8Array` is transferred zero-copy.
38
+ *
39
+ * **When it pays (measure — don't assume).** Threading only wins when per-item work is heavy relative to the ~µs
40
+ * cross-thread dispatch cost (structured-clone in + out). From real workloads: light per-row work — CSV/JSON parse,
41
+ * string normalize, `JSON.parse` — is _dispatch-bound_ and runs **0.3–0.9× of single-threaded (a net loss)**; ms-scale
42
+ * per-row work — model inference, geocoding, crypto/image ops — is where threads win. If the per-row cost isn't clearly
43
+ * milliseconds, benchmark against the single-threaded version before adopting.
44
+ *
45
+ * **Concurrency is not core count.** Heavy work that is I/O- or memory-bound (random reads into one large on-disk DB,
46
+ * anything sharing memory bandwidth) peaks _low_ — often ~2–3 workers — and then _degrades_, because the workers
47
+ * contend for the shared resource, not the CPU. Start small and sweep; don't reach for `availableParallelism()`. Only
48
+ * CPU-bound per-row work (pure compute) scales out toward the core count.
49
+ *
50
+ * All workers are terminated on completion, error, or early `return()`.
51
+ *
52
+ * @see `parallelMap` for the same shape on the caller's thread — it takes a closure, which is why it cannot cross a
53
+ * thread boundary and this takes a module path instead.
54
+ * @see The "Choosing a primitive" table in the README, which keys the decision off per-row work.
55
+ */
56
+ export declare function parallelMapWorkers<T, R = unknown>(source: AsyncIterable<T> | Iterable<T>, options: ParallelMapWorkersOptions): AsyncIterableIterator<R>;
57
+ //# sourceMappingURL=parallel-map-workers.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"parallel-map-workers.d.ts","sourceRoot":"","sources":["../../lib/parallel-map-workers.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAMH;;GAEG;AACH,MAAM,MAAM,eAAe,CAAC,CAAC,GAAG,OAAO,EAAE,CAAC,GAAG,OAAO,IAAI,CACvD,IAAI,EAAE,CAAC,EACP,GAAG,EAAE;IAAE,KAAK,EAAE,MAAM,CAAA;CAAE,KAClB,CAAC,GAAG,UAAU,GAAG,SAAS,GAAG,OAAO,CAAC,CAAC,GAAG,UAAU,GAAG,SAAS,CAAC,CAAA;AAErE,MAAM,WAAW,yBAAyB;IACzC;;OAEG;IACH,MAAM,EAAE,MAAM,GAAG,GAAG,CAAA;IACpB;;;;;OAKG;IACH,WAAW,EAAE,MAAM,CAAA;IACnB;;OAEG;IACH,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB;;OAEG;IACH,UAAU,CAAC,EAAE,OAAO,CAAA;CACpB;AAqCD;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,kBAAkB,CAAC,CAAC,EAAE,CAAC,GAAG,OAAO,EAChD,MAAM,EAAE,aAAa,CAAC,CAAC,CAAC,GAAG,QAAQ,CAAC,CAAC,CAAC,EACtC,OAAO,EAAE,yBAAyB,GAChC,qBAAqB,CAAC,CAAC,CAAC,CAyB1B"}
@@ -0,0 +1,82 @@
1
+ /**
2
+ * @copyright Sister Software
3
+ * @license MIT
4
+ * @author Teffen Ellis, et al.
5
+ */
6
+ import { Worker } from "node:worker_threads";
7
+ import { runPool } from "./parallel-map-runtime.js";
8
+ /**
9
+ * Wrap a worker as a pool slot: dispatch one batch, await its result. One batch in flight at a time.
10
+ */
11
+ function workerHandle(worker) {
12
+ let pending = null;
13
+ const settle = (fn) => {
14
+ if (!pending)
15
+ return;
16
+ const p = pending;
17
+ pending = null;
18
+ fn(p);
19
+ };
20
+ worker.on("message", (msg) => {
21
+ if (msg?.type === "result") {
22
+ settle((p) => p.resolve(msg.results));
23
+ }
24
+ else if (msg?.type === "error") {
25
+ settle((p) => p.reject(new Error(msg.message)));
26
+ }
27
+ });
28
+ worker.on("error", (error) => settle((p) => p.reject(error instanceof Error ? error : new Error(String(error)))));
29
+ return {
30
+ process(batch) {
31
+ return new Promise((resolve, reject) => {
32
+ pending = { resolve, reject };
33
+ worker.postMessage({ type: "batch", batch });
34
+ });
35
+ },
36
+ };
37
+ }
38
+ /**
39
+ * Map an async (or sync) iterable through a pool of worker threads. Main pulls items from `source`, batches them, and
40
+ * dispatches each batch to an idle worker running the `worker` handler module; results stream back as a single merged
41
+ * async iterator in **completion order** (not input order). A handler returning `undefined` drops that item; a
42
+ * `Uint8Array` is transferred zero-copy.
43
+ *
44
+ * **When it pays (measure — don't assume).** Threading only wins when per-item work is heavy relative to the ~µs
45
+ * cross-thread dispatch cost (structured-clone in + out). From real workloads: light per-row work — CSV/JSON parse,
46
+ * string normalize, `JSON.parse` — is _dispatch-bound_ and runs **0.3–0.9× of single-threaded (a net loss)**; ms-scale
47
+ * per-row work — model inference, geocoding, crypto/image ops — is where threads win. If the per-row cost isn't clearly
48
+ * milliseconds, benchmark against the single-threaded version before adopting.
49
+ *
50
+ * **Concurrency is not core count.** Heavy work that is I/O- or memory-bound (random reads into one large on-disk DB,
51
+ * anything sharing memory bandwidth) peaks _low_ — often ~2–3 workers — and then _degrades_, because the workers
52
+ * contend for the shared resource, not the CPU. Start small and sweep; don't reach for `availableParallelism()`. Only
53
+ * CPU-bound per-row work (pure compute) scales out toward the core count.
54
+ *
55
+ * All workers are terminated on completion, error, or early `return()`.
56
+ *
57
+ * @see `parallelMap` for the same shape on the caller's thread — it takes a closure, which is why it cannot cross a
58
+ * thread boundary and this takes a module path instead.
59
+ * @see The "Choosing a primitive" table in the README, which keys the decision off per-row work.
60
+ */
61
+ export function parallelMapWorkers(source, options) {
62
+ const handlerUrl = options.worker instanceof URL ? options.worker.href : new URL(options.worker, `file://${process.cwd()}/`).href;
63
+ const concurrency = Math.max(1, Math.floor(options.concurrency));
64
+ const batchSize = options.batchSize ?? 64;
65
+ const entryUrl = new URL("./parallel-map-worker-entry.js", import.meta.url);
66
+ const workers = [];
67
+ async function* run() {
68
+ try {
69
+ const pool = Array.from({ length: concurrency }, () => {
70
+ const worker = new Worker(entryUrl, { workerData: { handlerUrl, userData: options.workerData } });
71
+ workers.push(worker);
72
+ return workerHandle(worker);
73
+ });
74
+ yield* runPool(pool, source, batchSize);
75
+ }
76
+ finally {
77
+ await Promise.all(workers.map((worker) => worker.terminate()));
78
+ }
79
+ }
80
+ return run();
81
+ }
82
+ //# sourceMappingURL=parallel-map-workers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"parallel-map-workers.js","sourceRoot":"","sources":["../../lib/parallel-map-workers.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAA;AAE5C,OAAO,EAAmB,OAAO,EAAE,MAAM,2BAA2B,CAAA;AAgCpE;;GAEG;AACH,SAAS,YAAY,CAAO,MAAc;IACzC,IAAI,OAAO,GAA+E,IAAI,CAAA;IAE9F,MAAM,MAAM,GAAG,CAAC,EAA4C,EAAE,EAAE;QAC/D,IAAI,CAAC,OAAO;YAAE,OAAM;QACpB,MAAM,CAAC,GAAG,OAAO,CAAA;QACjB,OAAO,GAAG,IAAI,CAAA;QACd,EAAE,CAAC,CAAC,CAAC,CAAA;IACN,CAAC,CAAA;IAED,MAAM,CAAC,EAAE,CAAC,SAAS,EAAE,CAAC,GAA0E,EAAE,EAAE;QACnG,IAAI,GAAG,EAAE,IAAI,KAAK,QAAQ,EAAE,CAAC;YAC5B,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAA;QACtC,CAAC;aAAM,IAAI,GAAG,EAAE,IAAI,KAAK,OAAO,EAAE,CAAC;YAClC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CA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EAAE,OAAO,IAAI,CAAC,GAAG,CAAC,CAAA;IAC3E,MAAM,OAAO,GAAa,EAAE,CAAA;IAE5B,KAAK,SAAS,CAAC,CAAC,GAAG;QAClB,IAAI,CAAC;YACJ,MAAM,IAAI,GAAG,KAAK,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,WAAW,EAAE,EAAE,GAAG,EAAE;gBACrD,MAAM,MAAM,GAAG,IAAI,MAAM,CAAC,QAAQ,EAAE,EAAE,UAAU,EAAE,EAAE,UAAU,EAAE,QAAQ,EAAE,OAAO,CAAC,UAAU,EAAE,EAAE,CAAC,CAAA;gBACjG,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,CAAA;gBAEpB,OAAO,YAAY,CAAO,MAAM,CAAC,CAAA;YAClC,CAAC,CAAC,CAAA;YAEF,KAAK,CAAC,CAAC,OAAO,CAAC,IAAI,EAAE,MAAM,EAAE,SAAS,CAAC,CAAA;QACxC,CAAC;gBAAS,CAAC;YACV,MAAM,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,SAAS,EAAE,CAAC,CAAC,CAAA;QAC/D,CAAC;IACF,CAAC;IAED,OAAO,GAAG,EAAE,CAAA;AACb,CAAC"}
@@ -3,51 +3,26 @@
3
3
  * @license MIT
4
4
  * @author Teffen Ellis, et al.
5
5
  */
6
+ import { AsyncSequence, type ParallelMapSequenceOptions } from "./AsyncSequence.js";
6
7
  /**
7
- * Per-item handler a parallelMap worker module exports. `index` is per-worker monotonic.
8
- */
9
- export type ParallelHandler<T = unknown, R = unknown> = (item: T, ctx: {
10
- index: number;
11
- }) => R | Uint8Array | undefined | Promise<R | Uint8Array | undefined>;
12
- export interface ParallelMapOptions {
13
- /**
14
- * Worker module path/URL exporting `handleItem(item, ctx)`. Top-level code = per-worker init.
15
- */
16
- worker: string | URL;
17
- /**
18
- * Number of worker threads in the pool. Keep it SMALL for I/O- or memory-bound handlers (per-row DB lookups, large
19
- * shared datasets): throughput typically peaks at ~2–3 and _degrades_ past that as workers contend for the shared
20
- * resource — only CPU-bound handlers scale toward the core count. Also bounded by RAM (each worker re-inits its
21
- * deps). Sweep it for your workload rather than defaulting to `availableParallelism()`.
22
- */
23
- concurrency: number;
24
- /**
25
- * Items per dispatched batch. @default 64
26
- */
27
- batchSize?: number;
28
- /**
29
- * Forwarded to every worker via `workerData.userData` (must be structured-cloneable).
30
- */
31
- workerData?: unknown;
32
- }
33
- /**
34
- * Map an async (or sync) iterable through a pool of worker threads. Main pulls items from `source`, batches them, and
35
- * dispatches each batch to an idle worker running the `worker` handler module; results stream back as a single merged
36
- * async iterator in **completion order** (not input order). A handler returning `undefined` drops that item; a
37
- * `Uint8Array` is transferred zero-copy.
8
+ * Map an iterable through a callback with up to `concurrency` calls in flight, yielding in **completion order** — not
9
+ * input order.
10
+ *
11
+ * The callback is a closure, so every call runs on the caller's thread. This overlaps _latency_ — file reads, network
12
+ * round-trips, anything that spends its time waiting and does nothing for CPU-bound work, which still occupies the
13
+ * one thread it always did.
38
14
  *
39
- * **When it pays (measure don't assume).** Threading only wins when per-item work is heavy relative to the ~µs
40
- * cross-thread dispatch cost (structured-clone in + out). From real workloads: light per-row work — CSV/JSON parse,
41
- * string normalize, `JSON.parse` — is _dispatch-bound_ and runs **0.3–0.9× of single-threaded (a net loss)**; ms-scale
42
- * per-row work — model inference, geocoding, crypto/image ops — is where threads win. If the per-row cost isn't clearly
43
- * milliseconds, benchmark against the single-threaded version before adopting.
15
+ * **Concurrency is not core count.** Work that contends for a shared resource (one disk, one socket pool, one on-disk
16
+ * database) peaks _low_ often ~2–3 and then degrades. Sweep it.
44
17
  *
45
- * **Concurrency is not core count.** Heavy work that is I/O- or memory-bound (random reads into one large on-disk DB,
46
- * anything sharing memory bandwidth) peaks _low_ — often ~2–3 workers — and then _degrades_, because the workers
47
- * contend for the shared resource, not the CPU. Start small and sweep; don't reach for `availableParallelism()`. Only
48
- * CPU-bound per-row work (pure compute) scales out toward the core count.
18
+ * @param source The collection to map.
19
+ * @param fn The callback, receiving `(value, counter)`.
20
+ * @param options Concurrency ceiling and optional abort signal.
49
21
  *
50
- * All workers are terminated on completion, error, or early `return()`.
22
+ * @yields Each result, in completion order.
23
+ * @see {@linkcode parallelMapWorkers} to run the handler on worker threads instead — it takes a module path rather than
24
+ * a closure, because a closure cannot cross a thread boundary.
25
+ * @see The "Choosing a primitive" table in the README, which keys the decision off per-row work.
51
26
  */
52
- export declare function parallelMap<T, R = unknown>(source: AsyncIterable<T> | Iterable<T>, options: ParallelMapOptions): AsyncIterableIterator<R>;
27
+ export declare function parallelMap<T, U>(source: AsyncIterable<T> | Iterable<T>, fn: (value: T, counter: number) => U | PromiseLike<U>, options: ParallelMapSequenceOptions): AsyncSequence<U>;
53
28
  //# sourceMappingURL=parallel-map.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"parallel-map.d.ts","sourceRoot":"","sources":["../../lib/parallel-map.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAMH;;GAEG;AACH,MAAM,MAAM,eAAe,CAAC,CAAC,GAAG,OAAO,EAAE,CAAC,GAAG,OAAO,IAAI,CACvD,IAAI,EAAE,CAAC,EACP,GAAG,EAAE;IAAE,KAAK,EAAE,MAAM,CAAA;CAAE,KAClB,CAAC,GAAG,UAAU,GAAG,SAAS,GAAG,OAAO,CAAC,CAAC,GAAG,UAAU,GAAG,SAAS,CAAC,CAAA;AAErE,MAAM,WAAW,kBAAkB;IAClC;;OAEG;IACH,MAAM,EAAE,MAAM,GAAG,GAAG,CAAA;IACpB;;;;;OAKG;IACH,WAAW,EAAE,MAAM,CAAA;IACnB;;OAEG;IACH,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB;;OAEG;IACH,UAAU,CAAC,EAAE,OAAO,CAAA;CACpB;AAqCD;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,WAAW,CAAC,CAAC,EAAE,CAAC,GAAG,OAAO,EACzC,MAAM,EAAE,aAAa,CAAC,CAAC,CAAC,GAAG,QAAQ,CAAC,CAAC,CAAC,EACtC,OAAO,EAAE,kBAAkB,GACzB,qBAAqB,CAAC,CAAC,CAAC,CAyB1B"}
1
+ {"version":3,"file":"parallel-map.d.ts","sourceRoot":"","sources":["../../lib/parallel-map.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,aAAa,EAAE,KAAK,0BAA0B,EAAE,MAAM,oBAAoB,CAAA;AAEnF;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,WAAW,CAAC,CAAC,EAAE,CAAC,EAC/B,MAAM,EAAE,aAAa,CAAC,CAAC,CAAC,GAAG,QAAQ,CAAC,CAAC,CAAC,EACtC,EAAE,EAAE,CAAC,KAAK,EAAE,CAAC,EAAE,OAAO,EAAE,MAAM,KAAK,CAAC,GAAG,WAAW,CAAC,CAAC,CAAC,EACrD,OAAO,EAAE,0BAA0B,GACjC,aAAa,CAAC,CAAC,CAAC,CAElB"}
@@ -3,76 +3,28 @@
3
3
  * @license MIT
4
4
  * @author Teffen Ellis, et al.
5
5
  */
6
- import { Worker } from "node:worker_threads";
7
- import { runPool } from "./parallel-map-runtime.js";
6
+ import { AsyncSequence } from "./AsyncSequence.js";
8
7
  /**
9
- * Wrap a worker as a pool slot: dispatch one batch, await its result. One batch in flight at a time.
10
- */
11
- function workerHandle(worker) {
12
- let pending = null;
13
- const settle = (fn) => {
14
- if (!pending)
15
- return;
16
- const p = pending;
17
- pending = null;
18
- fn(p);
19
- };
20
- worker.on("message", (msg) => {
21
- if (msg?.type === "result") {
22
- settle((p) => p.resolve(msg.results));
23
- }
24
- else if (msg?.type === "error") {
25
- settle((p) => p.reject(new Error(msg.message)));
26
- }
27
- });
28
- worker.on("error", (error) => settle((p) => p.reject(error instanceof Error ? error : new Error(String(error)))));
29
- return {
30
- process(batch) {
31
- return new Promise((resolve, reject) => {
32
- pending = { resolve, reject };
33
- worker.postMessage({ type: "batch", batch });
34
- });
35
- },
36
- };
37
- }
38
- /**
39
- * Map an async (or sync) iterable through a pool of worker threads. Main pulls items from `source`, batches them, and
40
- * dispatches each batch to an idle worker running the `worker` handler module; results stream back as a single merged
41
- * async iterator in **completion order** (not input order). A handler returning `undefined` drops that item; a
42
- * `Uint8Array` is transferred zero-copy.
8
+ * Map an iterable through a callback with up to `concurrency` calls in flight, yielding in **completion order** not
9
+ * input order.
10
+ *
11
+ * The callback is a closure, so every call runs on the caller's thread. This overlaps _latency_ — file reads, network
12
+ * round-trips, anything that spends its time waiting — and does nothing for CPU-bound work, which still occupies the
13
+ * one thread it always did.
43
14
  *
44
- * **When it pays (measure don't assume).** Threading only wins when per-item work is heavy relative to the ~µs
45
- * cross-thread dispatch cost (structured-clone in + out). From real workloads: light per-row work — CSV/JSON parse,
46
- * string normalize, `JSON.parse` — is _dispatch-bound_ and runs **0.3–0.9× of single-threaded (a net loss)**; ms-scale
47
- * per-row work — model inference, geocoding, crypto/image ops — is where threads win. If the per-row cost isn't clearly
48
- * milliseconds, benchmark against the single-threaded version before adopting.
15
+ * **Concurrency is not core count.** Work that contends for a shared resource (one disk, one socket pool, one on-disk
16
+ * database) peaks _low_ often ~2–3 and then degrades. Sweep it.
49
17
  *
50
- * **Concurrency is not core count.** Heavy work that is I/O- or memory-bound (random reads into one large on-disk DB,
51
- * anything sharing memory bandwidth) peaks _low_ — often ~2–3 workers — and then _degrades_, because the workers
52
- * contend for the shared resource, not the CPU. Start small and sweep; don't reach for `availableParallelism()`. Only
53
- * CPU-bound per-row work (pure compute) scales out toward the core count.
18
+ * @param source The collection to map.
19
+ * @param fn The callback, receiving `(value, counter)`.
20
+ * @param options Concurrency ceiling and optional abort signal.
54
21
  *
55
- * All workers are terminated on completion, error, or early `return()`.
22
+ * @yields Each result, in completion order.
23
+ * @see {@linkcode parallelMapWorkers} to run the handler on worker threads instead — it takes a module path rather than
24
+ * a closure, because a closure cannot cross a thread boundary.
25
+ * @see The "Choosing a primitive" table in the README, which keys the decision off per-row work.
56
26
  */
57
- export function parallelMap(source, options) {
58
- const handlerUrl = options.worker instanceof URL ? options.worker.href : new URL(options.worker, `file://${process.cwd()}/`).href;
59
- const concurrency = Math.max(1, Math.floor(options.concurrency));
60
- const batchSize = options.batchSize ?? 64;
61
- const entryUrl = new URL("./parallel-map-worker-entry.js", import.meta.url);
62
- const workers = [];
63
- async function* run() {
64
- try {
65
- const pool = Array.from({ length: concurrency }, () => {
66
- const worker = new Worker(entryUrl, { workerData: { handlerUrl, userData: options.workerData } });
67
- workers.push(worker);
68
- return workerHandle(worker);
69
- });
70
- yield* runPool(pool, source, batchSize);
71
- }
72
- finally {
73
- await Promise.all(workers.map((worker) => worker.terminate()));
74
- }
75
- }
76
- return run();
27
+ export function parallelMap(source, fn, options) {
28
+ return AsyncSequence.from(source).parallelMap(fn, options);
77
29
  }
78
30
  //# sourceMappingURL=parallel-map.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"parallel-map.js","sourceRoot":"","sources":["../../lib/parallel-map.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAA;AAE5C,OAAO,EAAmB,OAAO,EAAE,MAAM,2BAA2B,CAAA;AAgCpE;;GAEG;AACH,SAAS,YAAY,CAAO,MAAc;IACzC,IAAI,OAAO,GAA+E,IAAI,CAAA;IAE9F,MAAM,MAAM,GAAG,CAAC,EAA4C,EAAE,EAAE;QAC/D,IAAI,CAAC,OAAO;YAAE,OAAM;QACpB,MAAM,CAAC,GAAG,OAAO,CAAA;QACjB,OAAO,GAAG,IAAI,CAAA;QACd,EAAE,CAAC,CAAC,CAAC,CAAA;IACN,CAAC,CAAA;IAED,MAAM,CAAC,EAAE,CAAC,SAAS,EAAE,CAAC,GAA0E,EAAE,EAAE;QACnG,IAAI,GAAG,EAAE,IAAI,KAAK,QAAQ,EAAE,CAAC;YAC5B,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,OAAO,C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M,CAAC,CAAC,WAAW,CAAC,EAAE,EAAE,OAAO,CAAC,CAAA;AAC3D,CAAC"}
@@ -0,0 +1,30 @@
1
+ /**
2
+ * @copyright Sister Software
3
+ * @license MIT
4
+ * @author Teffen Ellis, et al.
5
+ */
6
+ /**
7
+ * Given an iterable of values, maps each value to a record of the value and the result of the callback.
8
+ *
9
+ * This is a convenience function when an iterable needs mapping to an object-like structure.
10
+ *
11
+ * ```ts
12
+ * const iterable = ["a", "b", "c"]
13
+ * const result = pivot(iterable, (value) => value.toUpperCase())
14
+ *
15
+ * // { a: "A", b: "B", c: "C" }
16
+ * ```
17
+ *
18
+ * @category Collections
19
+ * @category Object
20
+ */
21
+ export declare function pivot<T extends PropertyKey, C extends (value: T) => Promise<unknown> | unknown>(
22
+ /**
23
+ * The iterable to pivot.
24
+ */
25
+ iterable: Iterable<T>,
26
+ /**
27
+ * The callback to transform each value.
28
+ */
29
+ callback: C): ReturnType<C> extends PromiseLike<infer U> ? Promise<Record<T, U>> : Record<T, ReturnType<C>>;
30
+ //# sourceMappingURL=pivot.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pivot.d.ts","sourceRoot":"","sources":["../../lib/pivot.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,KAAK,CAAC,CAAC,SAAS,WAAW,EAAE,CAAC,SAAS,CAAC,KAAK,EAAE,CAAC,KAAK,OAAO,CAAC,OAAO,CAAC,GAAG,OAAO;AAC9F;;GAEG;AACH,QAAQ,EAAE,QAAQ,CAAC,CAAC,CAAC;AACrB;;GAEG;AACH,QAAQ,EAAE,CAAC,GACT,UAAU,CAAC,CAAC,CAAC,SAAS,WAAW,CAAC,MAAM,CAAC,CAAC,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC,CAAC,EAAE,UAAU,CAAC,CAAC,CAAC,CAAC,CA6B/F"}
@@ -0,0 +1,47 @@
1
+ /**
2
+ * @copyright Sister Software
3
+ * @license MIT
4
+ * @author Teffen Ellis, et al.
5
+ */
6
+ /**
7
+ * Given an iterable of values, maps each value to a record of the value and the result of the callback.
8
+ *
9
+ * This is a convenience function when an iterable needs mapping to an object-like structure.
10
+ *
11
+ * ```ts
12
+ * const iterable = ["a", "b", "c"]
13
+ * const result = pivot(iterable, (value) => value.toUpperCase())
14
+ *
15
+ * // { a: "A", b: "B", c: "C" }
16
+ * ```
17
+ *
18
+ * @category Collections
19
+ * @category Object
20
+ */
21
+ export function pivot(
22
+ /**
23
+ * The iterable to pivot.
24
+ */
25
+ iterable,
26
+ /**
27
+ * The callback to transform each value.
28
+ */
29
+ callback) {
30
+ const entries = [];
31
+ let foundThenable = false;
32
+ for (const value of iterable) {
33
+ const result = callback(value);
34
+ if (result && typeof result === "object" && "then" in result) {
35
+ foundThenable = true;
36
+ }
37
+ entries.push([value, result]);
38
+ }
39
+ if (foundThenable) {
40
+ return Promise.all(entries.map(([key, value]) => {
41
+ return Promise.resolve(value).then((resolvedValue) => [key, resolvedValue]);
42
+ })).then(Object.fromEntries);
43
+ }
44
+ const pivotedRecord = Object.fromEntries(entries);
45
+ return pivotedRecord;
46
+ }
47
+ //# sourceMappingURL=pivot.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pivot.js","sourceRoot":"","sources":["../../lib/pivot.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;;;;;;;;;;;;;GAcG;AACH,MAAM,UAAU,KAAK;AACpB;;GAEG;AACH,QAAqB;AACrB;;GAEG;AACH,QAAW;IAEX,MAAM,OAAO,GAA8B,EAAE,CAAA;IAC7C,IAAI,aAAa,GAAG,KAAK,CAAA;IAEzB,KAAK,MAAM,KAAK,IAAI,QAAQ,EAAE,CAAC;QAC9B,MAAM,MAAM,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAA;QAE9B,IAAI,MAAM,IAAI,OAAO,MAAM,KAAK,QAAQ,IAAI,MAAM,IAAI,MAAM,EAAE,CAAC;YAC9D,aAAa,GAAG,IAAI,CAAA;QACrB,CAAC;QAED,OAAO,CAAC,IAAI,CAAC,CAAC,KAAK,EAAE,MAAuB,CAAC,CAAC,CAAA;IAC/C,CAAC;IAED,IAAI,aAAa,EAAE,CAAC;QACnB,OAAO,OAAO,CAAC,GAAG,CACjB,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,EAAE,EAAE;YAC5B,OAAO,OAAO,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,CAAC,aAAa,EAAE,EAAE,CAAC,CAAC,GAAG,EAAE,aAAa,CAAU,CAAC,CAAA;QACrF,CAAC,CAAC,CACF,CAAC,IAAI,CAAC,MAAM,CAAC,WAAW,CAEE,CAAA;IAC5B,CAAC;IAED,MAAM,aAAa,GAAG,MAAM,CAAC,WAAW,CAAC,OAAO,CAAC,CAAA;IAEjD,OAAO,aAEoB,CAAA;AAC5B,CAAC"}
@@ -152,31 +152,4 @@ export type DataResource = AsyncDataResource | TypedArray;
152
152
  export interface TextDecoderLike {
153
153
  decode(input: Uint8Array): string;
154
154
  }
155
- export type Zipped<T, U> = [a: T | undefined, b: U | undefined, idx: number];
156
- export type ZippedEntries<Z> = Z extends Zipped<infer T, infer U> ? [T, U] : never;
157
- export declare function zippedEntries<T, U>(zipped: Zipped<T, U>): ZippedEntries<Zipped<T, U>>;
158
- /**
159
- * Given two iterables, zip them together into a single iterable which yields pairs of elements.
160
- *
161
- * If one iterable is longer than the other, the shorter iterable will be padded with `undefined`.
162
- *
163
- * @param a The first iterable to zip.
164
- * @param b The second iterable to zip.
165
- *
166
- * @yields Pairs of elements from the two iterables.
167
- * @see {@linkcode zipAsync} for the asynchronous version.
168
- */
169
- export declare function zipSync<T, U>(a: Iterable<T>, b: Iterable<U>): Generator<Zipped<T, U>>;
170
- /**
171
- * Given two iterables, zip them together into a single iterable which yields pairs of elements.
172
- *
173
- * If one iterable is longer than the other, the shorter iterable will be padded with `undefined`.
174
- *
175
- * @param a The first iterable to zip.
176
- * @param b The second iterable to zip.
177
- *
178
- * @yields Pairs of elements from the two iterables.
179
- * @see {@linkcode zipSync} for the synchronous version.
180
- */
181
- export declare function zipAsync<T, U>(a: AsyncIterable<T> | Iterable<T>, b: AsyncIterable<U> | Iterable<U>): AsyncGenerator<[a: T | undefined, b: U | undefined, idx: number]>;
182
155
  //# sourceMappingURL=shared.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"shared.d.ts","sourceRoot":"","sources":["../../lib/shared.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,SAAS,CAAA;AAEpC,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAA;AAElD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAA;AAE9C;;GAEG;AACH,MAAM,MAAM,SAAS,GAAG,IAAI,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,GAAG,SAAS,CAAC,CAAA;AAEnE;;GAEG;AACH,MAAM,MAAM,cAAc,GAAG,IAAI,CAChC,UAAU,EACV,IAAI,GAAG,MAAM,GAAG,OAAO,GAAG,MAAM,GAAG,mBAAmB,GAAG,kBAAkB,CAC3E,CAAA;AAED;;GAEG;AACH,MAAM,MAAM,SAAS,GAAG;IACvB;;OAEG;IACH,KAAK,EAAE,MAAM;IACb;;OAEG;IACH,GAAG,EAAE,MAAM;CACX,CAAA;AAED;;GAEG;AACH,MAAM,MAAM,UAAU,GACnB,UAAU,GACV,iBAAiB,GACjB,WAAW,GACX,WAAW,GACX,SAAS,GACT,UAAU,GACV,UAAU,GACV,cAAc,GACd,aAAa,GACb,YAAY,GACZ,YAAY,CAAA;AAEf;;GAEG;AACH,MAAM,MAAM,cAAc,GAAG,cAAc,GAAG,UAAU,CAAA;AAExD;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,OAAO,GAAG,KA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W,CAAC,IAAI,CAAC,CAAA;CAC3C;AAED;;;;;;;;;GASG;AACH,MAAM,MAAM,iBAAiB,GAAG,MAAM,GAAG,GAAG,GAAG,cAAc,GAAG,kBAAkB,GAAG,eAAe,CAAA;AAEpG;;;;;GAKG;AACH,MAAM,MAAM,YAAY,GAAG,iBAAiB,GAAG,UAAU,CAAA;AAEzD;;GAEG;AACH,MAAM,WAAW,eAAe;IAC/B,MAAM,CAAC,KAAK,EAAE,UAAU,GAAG,MAAM,CAAA;CACjC"}
package/out/lib/shared.js CHANGED
@@ -38,57 +38,4 @@ export function applyReaderPolyfill(file) {
38
38
  },
39
39
  });
40
40
  }
41
- export function zippedEntries(zipped) {
42
- return zipped.slice(0, 2);
43
- }
44
- /**
45
- * Given two iterables, zip them together into a single iterable which yields pairs of elements.
46
- *
47
- * If one iterable is longer than the other, the shorter iterable will be padded with `undefined`.
48
- *
49
- * @param a The first iterable to zip.
50
- * @param b The second iterable to zip.
51
- *
52
- * @yields Pairs of elements from the two iterables.
53
- * @see {@linkcode zipAsync} for the asynchronous version.
54
- */
55
- export function* zipSync(a, b) {
56
- const aIterator = a[Symbol.iterator]();
57
- const bIterator = b[Symbol.iterator]();
58
- let index = 0;
59
- while (true) {
60
- const { done: aDone, value: aValue } = aIterator.next();
61
- const { done: bDone, value: bValue } = bIterator.next();
62
- if (aDone && bDone) {
63
- break;
64
- }
65
- yield [aValue, bValue, index];
66
- index++;
67
- }
68
- }
69
- /**
70
- * Given two iterables, zip them together into a single iterable which yields pairs of elements.
71
- *
72
- * If one iterable is longer than the other, the shorter iterable will be padded with `undefined`.
73
- *
74
- * @param a The first iterable to zip.
75
- * @param b The second iterable to zip.
76
- *
77
- * @yields Pairs of elements from the two iterables.
78
- * @see {@linkcode zipSync} for the synchronous version.
79
- */
80
- export async function* zipAsync(a, b) {
81
- const aIterator = Symbol.asyncIterator in a ? a[Symbol.asyncIterator]() : a[Symbol.iterator]();
82
- const bIterator = Symbol.asyncIterator in b ? b[Symbol.asyncIterator]() : b[Symbol.iterator]();
83
- let index = 0;
84
- while (true) {
85
- const { done: aDone, value: aValue } = await aIterator.next();
86
- const { done: bDone, value: bValue } = await bIterator.next();
87
- if (aDone && bDone) {
88
- break;
89
- }
90
- yield [aValue, bValue, index];
91
- index++;
92
- }
93
- }
94
41
  //# sourceMappingURL=shared.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"shared.js","sourceRoot":"","sources":["../../lib/shared.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAyDH;;GAEG;AACH,MAAM,UAAU,gBAAgB,CAAC,KAAc;IAC9C,OAAO,OAAO,CAAC,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,IAAI,IAAI,KAAK,CAAC,CAAA;AACpE,CAAC;AAuED;;GAEG;AACH,MAAM,UAAU,kBAAkB,CAAC,KAAc;IAChD,OAAO,OAAO,CAAC,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,OAAO,IAAI,KAAK,CAAC,CAAA;AACvE,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,mBAAmB,CAA6B,IAAO;IACtE,IAAI,MAAM,IAAI,IAAI,IAAI,OAAO,IAAI,CAAC,IAAI,KAAK,UAAU,EAAE,CAAC;QACvD,OAAM;IACP,CAAC;IAED,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE;QACnB,KAAK,CAAC,IAAI,CAAuB,OAAO,GAAsC,EAAE;YAC/E,MAAM,EAAE,QAAQ,EAAE,KAAK,GAAG,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC,IAAI,EAAE,MAAM,GAAG,CAAC,EAAE,GAAG,OAAO,CAAA;YACvE,MAAM,QAAQ,GAAG,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE,KAAK,GAAG,MAAM,CAAC,CAAA;YAElD,MAAM,KAAK,GAAG,CAAC,MAAM,QAAQ,CAAC,KAAK,EAAE,CAA0B,CAAA;YAE/D,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC;gBAC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D,OAAM;IACP,CAAC;IAED,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE;QACnB,KAAK,CAAC,IAAI,CAAuB,OAAO,GAAsC,EAAE;YAC/E,MAAM,EAAE,QAAQ,EAAE,KAAK,GAAG,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC,IAAI,EAAE,MAAM,GAAG,CAAC,EAAE,GAAG,OAAO,CAAA;YACvE,MAAM,QAAQ,GAAG,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE,KAAK,GAAG,MAAM,CAAC,CAAA;YAElD,MAAM,KAAK,GAAG,CAAC,MAAM,QAAQ,CAAC,KAAK,EAAE,CAA0B,CAAA;YAE/D,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC;gBACpB,MAAM,WAAW,GAAG,OAAO,CAAC,MAA+B,CAAA;gBAC3D,WAAW,CAAC,GAAG,CAAC,KAAY,EAAE,MAAM,CAAC,CAAA;gBAErC,OAAO,WAAW,CAAA;YACnB,CAAC;YAED,OAAO,KAAK,CAAA;QACb,CAAC;KACD,CAAC,CAAA;AACH,CAAC"}
package/out/lib/take.d.ts CHANGED
@@ -15,12 +15,28 @@
15
15
  * @yields The result of each callback execution
16
16
  */
17
17
  export declare function asyncParallelIterator<T, C extends (entry: T) => Promise<unknown>>(collection: Iterable<T> | AsyncIterable<T>, batchSize: number, callback: C, abortSignal?: AbortSignal): AsyncIterable<Awaited<ReturnType<C>>>;
18
+ /**
19
+ * Given an iterable, returns an array of arrays of the specified size.
20
+ *
21
+ * This is useful for batching asynchronous operations.
22
+ *
23
+ * @param collection The collection to batch.
24
+ * @param batchSize The size of each batch.
25
+ *
26
+ * @returns An iterable of arrays of the specified size.
27
+ * @see {@linkcode takeAsync} for the asynchronous version.
28
+ */
29
+ export declare function take<T>(collection: Iterable<T>, batchSize: number): Iterable<T[]>;
18
30
  /**
19
31
  * Given an async iterable collection, returns an async iterable, yielding batches of items.
20
32
  *
21
33
  * This is useful for emitting asynchronous items in batches, such as when processing a stream of data.
22
34
  *
35
+ * @param collection The async iterable collection to batch.
36
+ * @param batchSize The size of each batch.
37
+ *
23
38
  * @yields Each batch of items.
39
+ * @see {@linkcode take} for the synchronous version.
24
40
  */
25
41
  export declare function takeAsync<T>(collection: AsyncIterable<T>, batchSize: number): AsyncIterable<T[]>;
26
42
  //# sourceMappingURL=take.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"take.d.ts","sourceRoot":"","sources":["../../lib/take.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;;;;;;;;;GAUG;AACH,wBAAuB,qBAAqB,CAAC,CAAC,EAAE,CAAC,SAAS,CAAC,KAAK,EAAE,CAAC,KAAK,OAAO,CAAC,OAAO,CAAC,EACvF,UAAU,EAAE,QAAQ,CAAC,CAAC,CAAC,GAAG,aAAa,CAAC,CAAC,CAAC,EAC1C,SAAS,EAAE,MAAM,EACjB,QAAQ,EAAE,CAAC,EACX,WAAW,CAAC,EAAE,WAAW,GACvB,aAAa,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC,CAqDvC;AAED;;;;;;GAMG;AACH,wBAAuB,SAAS,CAAC,CAAC,EAAE,UAAU,EAAE,aAAa,CAAC,CAAC,CAAC,EAAE,SAAS,EAAE,MAAM,GAAG,aAAa,CAAC,CAAC,EAAE,CAAC,CAgBvG"}
1
+ {"version":3,"file":"take.d.ts","sourceRoot":"","sources":["../../lib/take.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;;;;;;;;;GAUG;AACH,wBAAuB,qBAAqB,CAAC,CAAC,EAAE,CAAC,SAAS,CAAC,KAAK,EAAE,CAAC,KAAK,OAAO,CAAC,OAAO,CAAC,EACvF,UAAU,EAAE,QAAQ,CAAC,CAAC,CAAC,GAAG,aAAa,CAAC,CAAC,CAAC,EAC1C,SAAS,EAAE,MAAM,EACjB,QAAQ,EAAE,CAAC,EACX,WAAW,CAAC,EAAE,WAAW,GACvB,aAAa,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC,CAqDvC;AAED;;;;;;;;;;GAUG;AACH,wBAAiB,IAAI,CAAC,CAAC,EAAE,UAAU,EAAE,QAAQ,CAAC,CAAC,CAAC,EAAE,SAAS,EAAE,MAAM,GAAG,QAAQ,CAAC,CAAC,EAAE,CAAC,CAgBlF;AAED;;;;;;;;;;GAUG;AACH,wBAAuB,SAAS,CAAC,CAAC,EAAE,UAAU,EAAE,aAAa,CAAC,CAAC,CAAC,EAAE,SAAS,EAAE,MAAM,GAAG,aAAa,CAAC,CAAC,EAAE,CAAC,CAgBvG"}
package/out/lib/take.js CHANGED
@@ -50,12 +50,40 @@ export async function* asyncParallelIterator(collection, batchSize, callback, ab
50
50
  }
51
51
  }
52
52
  }
53
+ /**
54
+ * Given an iterable, returns an array of arrays of the specified size.
55
+ *
56
+ * This is useful for batching asynchronous operations.
57
+ *
58
+ * @param collection The collection to batch.
59
+ * @param batchSize The size of each batch.
60
+ *
61
+ * @returns An iterable of arrays of the specified size.
62
+ * @see {@linkcode takeAsync} for the asynchronous version.
63
+ */
64
+ export function* take(collection, batchSize) {
65
+ const batch = [];
66
+ for (const item of collection) {
67
+ batch.push(item);
68
+ if (batch.length === batchSize) {
69
+ yield batch;
70
+ batch.length = 0;
71
+ }
72
+ }
73
+ if (batch.length) {
74
+ yield batch;
75
+ }
76
+ }
53
77
  /**
54
78
  * Given an async iterable collection, returns an async iterable, yielding batches of items.
55
79
  *
56
80
  * This is useful for emitting asynchronous items in batches, such as when processing a stream of data.
57
81
  *
82
+ * @param collection The async iterable collection to batch.
83
+ * @param batchSize The size of each batch.
84
+ *
58
85
  * @yields Each batch of items.
86
+ * @see {@linkcode take} for the synchronous version.
59
87
  */
60
88
  export async function* takeAsync(collection, batchSize) {
61
89
  let buffer = [];
@@ -1 +1 @@
1
- {"version":3,"file":"take.js","sourceRoot":"","sources":["../../lib/take.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;;;;;;;;;GAUG;AACH,MAAM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