@johnhenry/iteration 0.0.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.
Files changed (88) hide show
  1. package/MIT-LICENSE.txt +20 -0
  2. package/dist/abort.d.ts +26 -0
  3. package/dist/abort.d.ts.map +1 -0
  4. package/dist/abort.js +69 -0
  5. package/dist/abort.js.map +1 -0
  6. package/dist/assertions/eventualequal.d.ts +9 -0
  7. package/dist/assertions/eventualequal.d.ts.map +1 -0
  8. package/dist/assertions/eventualequal.js +30 -0
  9. package/dist/assertions/eventualequal.js.map +1 -0
  10. package/dist/async-channel.d.ts +101 -0
  11. package/dist/async-channel.d.ts.map +1 -0
  12. package/dist/async-channel.js +208 -0
  13. package/dist/async-channel.js.map +1 -0
  14. package/dist/channel-decorators.d.ts +23 -0
  15. package/dist/channel-decorators.d.ts.map +1 -0
  16. package/dist/channel-decorators.js +31 -0
  17. package/dist/channel-decorators.js.map +1 -0
  18. package/dist/concurrency.d.ts +43 -0
  19. package/dist/concurrency.d.ts.map +1 -0
  20. package/dist/concurrency.js +145 -0
  21. package/dist/concurrency.js.map +1 -0
  22. package/dist/consumers.d.ts +199 -0
  23. package/dist/consumers.d.ts.map +1 -0
  24. package/dist/consumers.js +349 -0
  25. package/dist/consumers.js.map +1 -0
  26. package/dist/count.d.ts +37 -0
  27. package/dist/count.d.ts.map +1 -0
  28. package/dist/count.js +70 -0
  29. package/dist/count.js.map +1 -0
  30. package/dist/empty-iterator.d.ts +15 -0
  31. package/dist/empty-iterator.d.ts.map +1 -0
  32. package/dist/empty-iterator.js +16 -0
  33. package/dist/empty-iterator.js.map +1 -0
  34. package/dist/eventualequal.d.ts +2 -0
  35. package/dist/eventualequal.d.ts.map +1 -0
  36. package/dist/eventualequal.js +54 -0
  37. package/dist/eventualequal.js.map +1 -0
  38. package/dist/exhaust.d.ts +7 -0
  39. package/dist/exhaust.d.ts.map +1 -0
  40. package/dist/exhaust.js +22 -0
  41. package/dist/exhaust.js.map +1 -0
  42. package/dist/index.d.ts +16 -0
  43. package/dist/index.d.ts.map +1 -0
  44. package/dist/index.js +16 -0
  45. package/dist/index.js.map +1 -0
  46. package/dist/is-iterator.d.ts +5 -0
  47. package/dist/is-iterator.d.ts.map +1 -0
  48. package/dist/is-iterator.js +5 -0
  49. package/dist/is-iterator.js.map +1 -0
  50. package/dist/iterator-tools.d.ts +164 -0
  51. package/dist/iterator-tools.d.ts.map +1 -0
  52. package/dist/iterator-tools.js +231 -0
  53. package/dist/iterator-tools.js.map +1 -0
  54. package/dist/itertools.d.ts +237 -0
  55. package/dist/itertools.d.ts.map +1 -0
  56. package/dist/itertools.js +471 -0
  57. package/dist/itertools.js.map +1 -0
  58. package/dist/tee.d.ts +18 -0
  59. package/dist/tee.d.ts.map +1 -0
  60. package/dist/tee.js +118 -0
  61. package/dist/tee.js.map +1 -0
  62. package/dist/transduce.d.ts +79 -0
  63. package/dist/transduce.d.ts.map +1 -0
  64. package/dist/transduce.js +37 -0
  65. package/dist/transduce.js.map +1 -0
  66. package/dist/transducers.d.ts +123 -0
  67. package/dist/transducers.d.ts.map +1 -0
  68. package/dist/transducers.js +212 -0
  69. package/dist/transducers.js.map +1 -0
  70. package/package.json +122 -0
  71. package/readme.md +761 -0
  72. package/src/abort.ts +80 -0
  73. package/src/assertions/eventualequal.ts +36 -0
  74. package/src/async-channel.ts +228 -0
  75. package/src/channel-decorators.ts +49 -0
  76. package/src/concurrency.ts +168 -0
  77. package/src/consumers.ts +425 -0
  78. package/src/count.ts +72 -0
  79. package/src/empty-iterator.ts +17 -0
  80. package/src/eventualequal.ts +54 -0
  81. package/src/exhaust.ts +26 -0
  82. package/src/index.ts +17 -0
  83. package/src/is-iterator.ts +9 -0
  84. package/src/iterator-tools.ts +290 -0
  85. package/src/itertools.ts +518 -0
  86. package/src/tee.ts +136 -0
  87. package/src/transduce.ts +161 -0
  88. package/src/transducers.ts +256 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,oBAAoB,CAAC;AACnC,cAAc,kBAAkB,CAAC;AACjC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,YAAY,CAAC;AAC3B,cAAc,qBAAqB,CAAC;AACpC,cAAc,cAAc,CAAC;AAC7B,cAAc,kBAAkB,CAAC;AACjC,cAAc,qBAAqB,CAAC;AACpC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,UAAU,CAAC;AACzB,cAAc,gBAAgB,CAAC;AAE/B,OAAO,KAAK,iBAAiB,MAAM,yBAAyB,CAAC;AAC7D,OAAO,KAAK,WAAW,MAAM,kBAAkB,CAAC;AAEhD,OAAO,EAAE,iBAAiB,EAAE,WAAW,EAAE,CAAC"}
@@ -0,0 +1,5 @@
1
+ export declare const isIterator: (obj: unknown) => obj is Iterable<unknown>;
2
+ export declare const isAsyncIterator: (obj: unknown) => obj is AsyncIterable<unknown>;
3
+ export declare const exhaustable: (obj: unknown) => boolean;
4
+ export default exhaustable;
5
+ //# sourceMappingURL=is-iterator.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"is-iterator.d.ts","sourceRoot":"","sources":["../src/is-iterator.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,UAAU,GAAI,KAAK,OAAO,KAAG,GAAG,IAAI,QAAQ,CAAC,OAAO,CACI,CAAC;AAEtE,eAAO,MAAM,eAAe,GAAI,KAAK,OAAO,KAAG,GAAG,IAAI,aAAa,CAAC,OAAO,CACI,CAAC;AAEhF,eAAO,MAAM,WAAW,GAAI,KAAK,OAAO,KAAG,OAAkD,CAAC;AAE9F,eAAe,WAAW,CAAC"}
@@ -0,0 +1,5 @@
1
+ export const isIterator = (obj) => typeof obj?.[Symbol.iterator] === "function";
2
+ export const isAsyncIterator = (obj) => typeof obj?.[Symbol.asyncIterator] === "function";
3
+ export const exhaustable = (obj) => isIterator(obj) || isAsyncIterator(obj);
4
+ export default exhaustable;
5
+ //# sourceMappingURL=is-iterator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"is-iterator.js","sourceRoot":"","sources":["../src/is-iterator.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,GAAY,EAA4B,EAAE,CACnE,OAAQ,GAAyB,EAAE,CAAC,MAAM,CAAC,QAAQ,CAAC,KAAK,UAAU,CAAC;AAEtE,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,GAAY,EAAiC,EAAE,CAC7E,OAAQ,GAA8B,EAAE,CAAC,MAAM,CAAC,aAAa,CAAC,KAAK,UAAU,CAAC;AAEhF,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,GAAY,EAAW,EAAE,CAAC,UAAU,CAAC,GAAG,CAAC,IAAI,eAAe,CAAC,GAAG,CAAC,CAAC;AAE9F,eAAe,WAAW,CAAC"}
@@ -0,0 +1,164 @@
1
+ /**
2
+ * Sentinel returned by a reducer step to stop consumption of the source
3
+ * iterator (early termination -- see the `take` transducer).
4
+ */
5
+ export declare const HALT: unique symbol;
6
+ export type Halt = typeof HALT;
7
+ /**
8
+ * @deprecated Misspelled legacy alias of {@link HALT} (pre-2.1 name).
9
+ * Kept for backwards compatibility; prefer HALT.
10
+ */
11
+ export { HALT as HAULT };
12
+ /**
13
+ * The transducer step protocol (v2.1, "pending-emission buffer").
14
+ *
15
+ * The accumulator is a plain array used as a pending-emission buffer: the
16
+ * innermost step ("emit" -- see transduce.ts) pushes emitted items onto it
17
+ * and returns it. A step may instead return {@link HALT} to terminate
18
+ * consumption of the source early. A stateful step (e.g. `group`,
19
+ * `partitionBy`) may carry a `complete` method, invoked once after the
20
+ * source is exhausted (or halted) to flush buffered state; `complete`
21
+ * implementations must cascade to their inner step's own `complete` (see
22
+ * transducers.ts).
23
+ */
24
+ export interface ReducerStep<in In> {
25
+ (buffer: unknown[], item: In, iterator?: Iterable<In> | AsyncIterable<In>): unknown[] | Halt;
26
+ complete?: (buffer: unknown[]) => unknown[];
27
+ }
28
+ /**
29
+ * A transducer: transforms a step that consumes `Out` items into a step
30
+ * that consumes `In` items. Produced by the factories in transducers.ts
31
+ * (map, filter, take, group, ...), consumed by transduceSync/transduceAsync
32
+ * (left-to-right composition as written).
33
+ */
34
+ export type Transducer<In, Out> = (next: ReducerStep<Out>) => ReducerStep<In>;
35
+ /**
36
+ * Create a promise that fulfills after a given number of milliseconds
37
+ * The primary purpose of this is to allow pausing of asynchronous functions
38
+ * @kind function
39
+ * @name pause
40
+ * @param milliseconds time in milliseconds before value is resolved
41
+ * @param value value given
42
+ * @returns Promise fulfilled with given value
43
+ * @example <caption>Pause a function for 5000 milliseconds</caption>
44
+ * ```javascript
45
+ * import { pause } from '...';
46
+ * (async ()=>{
47
+ * console.log('hello');
48
+ * await pause(5000);
49
+ * console.log('there.');
50
+ * })();
51
+ * ```
52
+ */
53
+ export declare const pause: <T = undefined>(milliseconds: number, value?: T) => Promise<T>;
54
+ /**
55
+ * Streaming reduce for iterators -- the engine under transduceSync.
56
+ *
57
+ * Protocol (v2.1): the accumulator (`init`) is a plain array used as a
58
+ * *pending-emission buffer*, not a threaded iterable. The innermost step
59
+ * ("emit" -- see transduce.ts) pushes emitted items onto the buffer and
60
+ * returns it; after each step call the buffer is drained (yielded out and
61
+ * cleared in place). This replaces the v2.0 protocol, in which the
62
+ * accumulator was an iterable that each step wrapped in a fresh generator
63
+ * (`conjoin(init, item)`) -- that formed an ever-growing generator chain
64
+ * retaining ~176 bytes per item processed, i.e. unbounded heap growth on
65
+ * long streams.
66
+ *
67
+ * Preserved semantics:
68
+ * - Left-to-right composition order as written in transduceSync(...fns).
69
+ * - If `step` carries a `.complete(init)` method (the transducer completion
70
+ * protocol -- see transducers.ts's `group`/`partitionBy`), it is invoked
71
+ * once after the source iterator is exhausted (or halted), letting
72
+ * stateful transducers flush buffered state (e.g. a trailing,
73
+ * under-sized `group`).
74
+ * - HALT early termination: a step returning HALT stops consumption of
75
+ * the source; emissions buffered during the halting step itself are
76
+ * discarded (as in v2.0, where the halting step's accumulator chain was
77
+ * dropped), then `.complete` still flushes.
78
+ * @kind function
79
+ * @name reduceSync
80
+ * @param iterator source iterable
81
+ * @param step reducer/transducer step function
82
+ * @param init pending-emission buffer (defaults to a fresh array)
83
+ * @param ignore_halt ignore when HALT is passed
84
+ * @returns generator yielding each emitted item
85
+ */
86
+ export declare const reduceSync: <In, Out = unknown>(iterator: Iterable<In>, step: ReducerStep<In>, init?: unknown[], ignore_halt?: boolean) => Generator<Out>;
87
+ /**
88
+ * Streaming reduce for asynchronous iterators -- the engine under
89
+ * transduceAsync. See reduceSync for the pending-emission-buffer protocol
90
+ * (v2.1), the `.complete` flush protocol, and HALT semantics -- all
91
+ * identical here, just async.
92
+ * @kind function
93
+ * @name reduceAsync
94
+ * @param iterator source (async) iterable
95
+ * @param step reducer/transducer step function
96
+ * @param init pending-emission buffer (defaults to a fresh array)
97
+ * @param ignore_halt ignore when HALT is passed
98
+ * @returns async generator yielding each emitted item
99
+ */
100
+ export declare const reduceAsync: <In, Out = unknown>(iterator: AsyncIterable<In> | Iterable<In>, step: ReducerStep<In>, init?: unknown[], ignore_halt?: boolean) => AsyncGenerator<Out>;
101
+ /**
102
+ * Concatinates sequence of synchronous iterables
103
+ * @kind function
104
+ * @name concatSync
105
+ * @param iterators iterators
106
+ * @returns iterator generating sequence of combined from given iterables; empty iterator if nothing is passed
107
+ */
108
+ export declare const concatSync: <T>(...iterators: Array<Iterable<T>>) => Generator<T>;
109
+ /**
110
+ * Appends items to synchronous iterator
111
+ * @kind function
112
+ * @name conjoinSync
113
+ * @param iterator iterator
114
+ * @param itemList items to be appended
115
+ * @returns copy of initial iterator with items appended
116
+ */
117
+ export declare const conjoinSync: <T>(iterator?: Iterable<T>, ...itemList: T[]) => Generator<T>;
118
+ /**
119
+ * Concatinates sequence of asynchronous iterables
120
+ * @kind function
121
+ * @name concatAsync
122
+ * @param iterators iterators
123
+ * @returns iterator generating sequence of combined from given iterables; empty iterator if nothing is passed
124
+ */
125
+ export declare const concatAsync: <T>(...iterators: Array<AsyncIterable<T> | Iterable<T>>) => AsyncGenerator<T>;
126
+ /**
127
+ * Appends items to asynchronous iterator
128
+ * @kind function
129
+ * @name conjoinAsync
130
+ * @param iterator iterator
131
+ * @param itemList items to be appended
132
+ * @returns copy of initial iterator with items appended
133
+ */
134
+ export declare const conjoinAsync: <T>(iterator?: AsyncIterable<T> | Iterable<T>, ...itemList: T[]) => AsyncGenerator<T>;
135
+ /**
136
+ * Zips synchronous iterators
137
+ * @kind function
138
+ * @name zipSync
139
+ * @param iteratorList iterators
140
+ * @returns an iterator who's members are the members of the given iterators zipped sequencially
141
+ */
142
+ export declare const zipSync: <T>(...iteratorList: Array<Iterable<T>>) => Generator<T[]>;
143
+ /**
144
+ * Zips asynchronous iterators (dual of zipSync).
145
+ * Pulls the next value from every input in parallel each round (rather than
146
+ * sequentially awaiting one at a time), stopping as soon as any input is
147
+ * exhausted -- matching zipSync's stop-at-shortest semantics.
148
+ * @kind function
149
+ * @name zipAsync
150
+ * @param iteratorList (async or sync) iterators
151
+ * @returns an async iterator who's members are the members of the given iterators zipped sequencially
152
+ */
153
+ export declare const zipAsync: <T>(...iteratorList: Array<AsyncIterable<T> | Iterable<T>>) => AsyncGenerator<T[]>;
154
+ /**
155
+ * "run" iterator as a program
156
+ * @kind function
157
+ * @name run
158
+ * @param program iterator
159
+ * @param render function to render output from iterator
160
+ */
161
+ export declare const run: <T>(program: AsyncIterable<T> | Iterable<T>, render?: (output: T) => unknown) => Promise<void>;
162
+ export declare const syncFrom: <T>(...stuff: T[]) => Generator<T>;
163
+ export declare const asyncFrom: <T>(...stuff: T[]) => AsyncGenerator<T>;
164
+ //# sourceMappingURL=iterator-tools.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"iterator-tools.d.ts","sourceRoot":"","sources":["../src/iterator-tools.ts"],"names":[],"mappings":"AAEA;;;GAGG;AACH,eAAO,MAAM,IAAI,EAAE,OAA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M,EAAE,CAAC,KAAK,OAAqB,KAC3C,OAAO,CAAC,IAAI,CAId,CAAC;AAEF,eAAO,MAAM,QAAQ,GAAc,CAAC,EAAE,GAAG,OAAO,CAAC,EAAE,KAAG,SAAS,CAAC,CAAC,CAIhE,CAAC;AACF,eAAO,MAAM,SAAS,GAAoB,CAAC,EAAE,GAAG,OAAO,CAAC,EAAE,KAAG,cAAc,CAAC,CAAC,CAI5E,CAAC"}
@@ -0,0 +1,231 @@
1
+ import { isAsyncIterator } from "./is-iterator.js";
2
+ /**
3
+ * Sentinel returned by a reducer step to stop consumption of the source
4
+ * iterator (early termination -- see the `take` transducer).
5
+ */
6
+ export const HALT = Symbol("HALT");
7
+ /**
8
+ * @deprecated Misspelled legacy alias of {@link HALT} (pre-2.1 name).
9
+ * Kept for backwards compatibility; prefer HALT.
10
+ */
11
+ export { HALT as HAULT };
12
+ /**
13
+ * Create a promise that fulfills after a given number of milliseconds
14
+ * The primary purpose of this is to allow pausing of asynchronous functions
15
+ * @kind function
16
+ * @name pause
17
+ * @param milliseconds time in milliseconds before value is resolved
18
+ * @param value value given
19
+ * @returns Promise fulfilled with given value
20
+ * @example <caption>Pause a function for 5000 milliseconds</caption>
21
+ * ```javascript
22
+ * import { pause } from '...';
23
+ * (async ()=>{
24
+ * console.log('hello');
25
+ * await pause(5000);
26
+ * console.log('there.');
27
+ * })();
28
+ * ```
29
+ */
30
+ export const pause = (milliseconds, value) => new Promise((resolve) => setTimeout(resolve, milliseconds, value));
31
+ /**
32
+ * Streaming reduce for iterators -- the engine under transduceSync.
33
+ *
34
+ * Protocol (v2.1): the accumulator (`init`) is a plain array used as a
35
+ * *pending-emission buffer*, not a threaded iterable. The innermost step
36
+ * ("emit" -- see transduce.ts) pushes emitted items onto the buffer and
37
+ * returns it; after each step call the buffer is drained (yielded out and
38
+ * cleared in place). This replaces the v2.0 protocol, in which the
39
+ * accumulator was an iterable that each step wrapped in a fresh generator
40
+ * (`conjoin(init, item)`) -- that formed an ever-growing generator chain
41
+ * retaining ~176 bytes per item processed, i.e. unbounded heap growth on
42
+ * long streams.
43
+ *
44
+ * Preserved semantics:
45
+ * - Left-to-right composition order as written in transduceSync(...fns).
46
+ * - If `step` carries a `.complete(init)` method (the transducer completion
47
+ * protocol -- see transducers.ts's `group`/`partitionBy`), it is invoked
48
+ * once after the source iterator is exhausted (or halted), letting
49
+ * stateful transducers flush buffered state (e.g. a trailing,
50
+ * under-sized `group`).
51
+ * - HALT early termination: a step returning HALT stops consumption of
52
+ * the source; emissions buffered during the halting step itself are
53
+ * discarded (as in v2.0, where the halting step's accumulator chain was
54
+ * dropped), then `.complete` still flushes.
55
+ * @kind function
56
+ * @name reduceSync
57
+ * @param iterator source iterable
58
+ * @param step reducer/transducer step function
59
+ * @param init pending-emission buffer (defaults to a fresh array)
60
+ * @param ignore_halt ignore when HALT is passed
61
+ * @returns generator yielding each emitted item
62
+ */
63
+ export const reduceSync = function* (iterator, step, init = [], ignore_halt = false) {
64
+ for (const item of iterator) {
65
+ const next = step(init, item, iterator);
66
+ if (!ignore_halt && next === HALT) {
67
+ init.length = 0;
68
+ break;
69
+ }
70
+ init = next;
71
+ while (init.length > 0) {
72
+ yield init.shift();
73
+ }
74
+ }
75
+ if (step.complete) {
76
+ init = step.complete(init);
77
+ while (init.length > 0) {
78
+ yield init.shift();
79
+ }
80
+ }
81
+ };
82
+ /**
83
+ * Streaming reduce for asynchronous iterators -- the engine under
84
+ * transduceAsync. See reduceSync for the pending-emission-buffer protocol
85
+ * (v2.1), the `.complete` flush protocol, and HALT semantics -- all
86
+ * identical here, just async.
87
+ * @kind function
88
+ * @name reduceAsync
89
+ * @param iterator source (async) iterable
90
+ * @param step reducer/transducer step function
91
+ * @param init pending-emission buffer (defaults to a fresh array)
92
+ * @param ignore_halt ignore when HALT is passed
93
+ * @returns async generator yielding each emitted item
94
+ */
95
+ export const reduceAsync = async function* (iterator, step, init = [], ignore_halt = false) {
96
+ for await (const item of iterator) {
97
+ const next = step(init, item, iterator);
98
+ if (!ignore_halt && next === HALT) {
99
+ init.length = 0;
100
+ break;
101
+ }
102
+ init = next;
103
+ while (init.length > 0) {
104
+ yield init.shift();
105
+ }
106
+ }
107
+ if (step.complete) {
108
+ init = step.complete(init);
109
+ while (init.length > 0) {
110
+ yield init.shift();
111
+ }
112
+ }
113
+ };
114
+ /**
115
+ * Concatinates sequence of synchronous iterables
116
+ * @kind function
117
+ * @name concatSync
118
+ * @param iterators iterators
119
+ * @returns iterator generating sequence of combined from given iterables; empty iterator if nothing is passed
120
+ */
121
+ export const concatSync = function* (...iterators) {
122
+ for (const iterator of iterators) {
123
+ yield* iterator;
124
+ }
125
+ };
126
+ /**
127
+ * Appends items to synchronous iterator
128
+ * @kind function
129
+ * @name conjoinSync
130
+ * @param iterator iterator
131
+ * @param itemList items to be appended
132
+ * @returns copy of initial iterator with items appended
133
+ */
134
+ export const conjoinSync = function* (iterator, ...itemList) {
135
+ if (iterator) {
136
+ yield* iterator;
137
+ }
138
+ yield* itemList;
139
+ };
140
+ /**
141
+ * Concatinates sequence of asynchronous iterables
142
+ * @kind function
143
+ * @name concatAsync
144
+ * @param iterators iterators
145
+ * @returns iterator generating sequence of combined from given iterables; empty iterator if nothing is passed
146
+ */
147
+ export const concatAsync = async function* (...iterators) {
148
+ for (const iterator of iterators) {
149
+ yield* iterator;
150
+ }
151
+ };
152
+ /**
153
+ * Appends items to asynchronous iterator
154
+ * @kind function
155
+ * @name conjoinAsync
156
+ * @param iterator iterator
157
+ * @param itemList items to be appended
158
+ * @returns copy of initial iterator with items appended
159
+ */
160
+ export const conjoinAsync = async function* (iterator, ...itemList) {
161
+ if (iterator) {
162
+ yield* iterator;
163
+ }
164
+ yield* itemList;
165
+ };
166
+ /**
167
+ * Zips synchronous iterators
168
+ * @kind function
169
+ * @name zipSync
170
+ * @param iteratorList iterators
171
+ * @returns an iterator who's members are the members of the given iterators zipped sequencially
172
+ */
173
+ export const zipSync = function* (...iteratorList) {
174
+ const generators = iteratorList.map((iterator) => iterator[Symbol.iterator]());
175
+ outer: while (true) {
176
+ const result = [];
177
+ for (const generator of generators) {
178
+ const { value, done } = generator.next();
179
+ if (done) {
180
+ break outer;
181
+ }
182
+ result.push(value);
183
+ }
184
+ yield result;
185
+ }
186
+ };
187
+ /**
188
+ * Zips asynchronous iterators (dual of zipSync).
189
+ * Pulls the next value from every input in parallel each round (rather than
190
+ * sequentially awaiting one at a time), stopping as soon as any input is
191
+ * exhausted -- matching zipSync's stop-at-shortest semantics.
192
+ * @kind function
193
+ * @name zipAsync
194
+ * @param iteratorList (async or sync) iterators
195
+ * @returns an async iterator who's members are the members of the given iterators zipped sequencially
196
+ */
197
+ export const zipAsync = async function* (...iteratorList) {
198
+ const generators = iteratorList.map((iterator) => isAsyncIterator(iterator)
199
+ ? iterator[Symbol.asyncIterator]()
200
+ : iterator[Symbol.iterator]());
201
+ while (true) {
202
+ const results = await Promise.all(generators.map((g) => g.next()));
203
+ if (results.some(({ done }) => done)) {
204
+ break;
205
+ }
206
+ yield results.map(({ value }) => value);
207
+ }
208
+ };
209
+ /**
210
+ * "run" iterator as a program
211
+ * @kind function
212
+ * @name run
213
+ * @param program iterator
214
+ * @param render function to render output from iterator
215
+ */
216
+ export const run = async (program, render = console.log) => {
217
+ for await (const output of program) {
218
+ await render(output);
219
+ }
220
+ };
221
+ export const syncFrom = function* (...stuff) {
222
+ for (const thing of stuff) {
223
+ yield thing;
224
+ }
225
+ };
226
+ export const asyncFrom = async function* (...stuff) {
227
+ for (const thing of stuff) {
228
+ yield thing;
229
+ }
230
+ };
231
+ //# sourceMappingURL=iterator-tools.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"iterator-tools.js","sourceRoot":"","sources":["../src/iterator-tools.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAEnD;;;GAGG;AACH,MAAM,CAAC,MAAM,IAAI,GAAkB,MAAM,CAAC,MAAM,CAAC,CAAC;AAGlD;;;GAGG;A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AAE,CACjD,CAAC;IACF,OAAO,IAAI,EAAE,CAAC;QACZ,MAAM,OAAO,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC;QACnE,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC,EAAE,IAAI,EAAE,EAAE,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC;YACrC,MAAM;QACR,CAAC;QACD,MAAM,OAAO,CAAC,GAAG,CAAC,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE,CAAC,KAAU,CAAC,CAAC;IAC/C,CAAC;AACH,CAAC,CAAC;AAEF;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,GAAG,GAAG,KAAK,EACtB,OAAuC,EACvC,SAAiC,OAAO,CAAC,GAAG,EAC7B,EAAE;IACjB,IAAI,KAAK,EAAE,MAAM,MAAM,IAAI,OAAO,EAAE,CAAC;QACnC,MAAM,MAAM,CAAC,MAAM,CAAC,CAAC;IACvB,CAAC;AACH,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,QAAQ,GAAG,QAAQ,CAAC,EAAK,GAAG,KAAU;IACjD,KAAK,MAAM,KAAK,IAAI,KAAK,EAAE,CAAC;QAC1B,MAAM,KAAK,CAAC;IACd,CAAC;AACH,CAAC,CAAC;AACF,MAAM,CAAC,MAAM,SAAS,GAAG,KAAK,SAAS,CAAC,EAAK,GAAG,KAAU;IACxD,KAAK,MAAM,KAAK,IAAI,KAAK,EAAE,CAAC;QAC1B,MAAM,KAAK,CAAC;IACd,CAAC;AACH,CAAC,CAAC"}
@@ -0,0 +1,237 @@
1
+ /**
2
+ * Python itertools-parity building blocks.
3
+ *
4
+ * Unlike the curried transducer factories in transducers.ts (which are
5
+ * shaped `(...) => (conjoin) => (init, item) => ...` for composition inside
6
+ * transduceSync/transduceAsync), the functions here are flat, direct
7
+ * iterable-in/iterable-out generators -- matching Python's itertools
8
+ * argument order (predicate/fn first, iterable(s) last) so porting a
9
+ * Python recipe is close to mechanical.
10
+ *
11
+ * Where a sync function's behavior is fully covered by native ES2025
12
+ * Iterator Helpers (Iterator.prototype.map/filter/...), it's implemented
13
+ * as a thin wrapper around Iterator.from(iterable) rather than a hand-rolled
14
+ * generator, to keep the maintenance surface small. Async counterparts are
15
+ * always hand-rolled async generators, since AsyncIterator helpers are not
16
+ * yet shipped (TC39 Stage 2).
17
+ *
18
+ * See docs/discussion/python-itertools.md for the full comparison to
19
+ * Python's itertools module and the documented design divergences.
20
+ */
21
+ /**
22
+ * Yield items while predicate holds; stop (without consuming further) at
23
+ * the first item that fails it. Predicate-based complement to the
24
+ * numeric `take` transducer.
25
+ * @kind function
26
+ * @name takeWhileSync
27
+ */
28
+ export declare function takeWhileSync<T>(predicate: (item: T) => boolean, iterable: Iterable<T>): Generator<T>;
29
+ /**
30
+ * Asynchronous dual of takeWhileSync.
31
+ * @kind function
32
+ * @name takeWhileAsync
33
+ */
34
+ export declare function takeWhileAsync<T>(predicate: (item: T) => boolean, iterable: AsyncIterable<T> | Iterable<T>): AsyncGenerator<T>;
35
+ /**
36
+ * Drop items while predicate holds, then yield everything else.
37
+ * Predicate-based complement to the numeric `drop` transducer.
38
+ * @kind function
39
+ * @name dropWhileSync
40
+ */
41
+ export declare function dropWhileSync<T>(predicate: (item: T) => boolean, iterable: Iterable<T>): Generator<T>;
42
+ /**
43
+ * Asynchronous dual of dropWhileSync.
44
+ * @kind function
45
+ * @name dropWhileAsync
46
+ */
47
+ export declare function dropWhileAsync<T>(predicate: (item: T) => boolean, iterable: AsyncIterable<T>): AsyncGenerator<T>;
48
+ /**
49
+ * Select items from `iterable` for which the parallel `selectors` iterable
50
+ * is truthy. Mirrors Python's itertools.compress(data, selectors).
51
+ * @kind function
52
+ * @name compressSync
53
+ */
54
+ export declare function compressSync<T>(iterable: Iterable<T>, selectors: Iterable<unknown>): Generator<T>;
55
+ /**
56
+ * Asynchronous dual of compressSync.
57
+ * @kind function
58
+ * @name compressAsync
59
+ */
60
+ export declare function compressAsync<T>(iterable: AsyncIterable<T> | Iterable<T>, selectors: AsyncIterable<unknown> | Iterable<unknown>): AsyncGenerator<T>;
61
+ /**
62
+ * Yield overlapping windows of `n` consecutive items.
63
+ * @kind function
64
+ * @name windowedSync
65
+ */
66
+ export declare function windowedSync<T>(iterable: Iterable<T>, n: number): Generator<T[]>;
67
+ /**
68
+ * Asynchronous dual of windowedSync.
69
+ * @kind function
70
+ * @name windowedAsync
71
+ */
72
+ export declare function windowedAsync<T>(iterable: AsyncIterable<T> | Iterable<T>, n: number): AsyncGenerator<T[]>;
73
+ /**
74
+ * Yield successive overlapping pairs. Mirrors Python 3.10+'s
75
+ * itertools.pairwise -- a thin call to windowedSync(iterable, 2) so the
76
+ * ring-buffer logic isn't duplicated.
77
+ * @kind function
78
+ * @name pairwiseSync
79
+ */
80
+ export declare function pairwiseSync<T>(iterable: Iterable<T>): Generator<[T, T]>;
81
+ /**
82
+ * Asynchronous dual of pairwiseSync.
83
+ * @kind function
84
+ * @name pairwiseAsync
85
+ */
86
+ export declare function pairwiseAsync<T>(iterable: AsyncIterable<T> | Iterable<T>): AsyncGenerator<[T, T]>;
87
+ /**
88
+ * Group consecutive items sharing a key into `[key, items[]]` pairs.
89
+ * Mirrors Python's itertools.groupby, but deliberately diverges from it:
90
+ * Python's sub-iterators are lazy and invalidated by the next outer
91
+ * `next()` call (a well-known footgun); this eagerly materializes each
92
+ * run as an array instead, which is safer and matches what JS developers
93
+ * expect. As in Python, only *consecutive* runs are grouped -- sort the
94
+ * input first if you want all occurrences of a key merged globally.
95
+ * @kind function
96
+ * @name groupBySync
97
+ */
98
+ export declare function groupBySync<T, K = T>(iterable: Iterable<T>, keyFn?: (item: T) => K): Generator<[K, T[]]>;
99
+ /**
100
+ * Asynchronous dual of groupBySync.
101
+ * @kind function
102
+ * @name groupByAsync
103
+ */
104
+ export declare function groupByAsync<T, K = T>(iterable: AsyncIterable<T>, keyFn?: (item: T) => K): AsyncGenerator<[K, T[]]>;
105
+ /**
106
+ * Chain multiple iterables into one sequence. Mirrors Python's
107
+ * itertools.chain(*iterables); an itertools-parity alias of concatSync.
108
+ * @kind function
109
+ * @name chainSync
110
+ * @see flattenSync
111
+ */
112
+ export declare const chainSync: <T>(...iterators: Array<Iterable<T>>) => Generator<T>;
113
+ /**
114
+ * Asynchronous dual of chainSync; alias of concatAsync.
115
+ * @kind function
116
+ * @name chainAsync
117
+ * @see flattenAsync
118
+ */
119
+ export declare const chainAsync: <T>(...iterators: Array<AsyncIterable<T> | Iterable<T>>) => AsyncGenerator<T>;
120
+ /**
121
+ * Flatten one level of an iterable-of-iterables. Mirrors Python's
122
+ * itertools.chain.from_iterable -- the single-arg counterpart to
123
+ * chainSync's variadic form. Not recursive.
124
+ * @kind function
125
+ * @name flattenSync
126
+ * @see chainSync
127
+ */
128
+ export declare function flattenSync<T>(iterableOfIterables: Iterable<Iterable<T>>): Generator<T>;
129
+ /**
130
+ * Asynchronous dual of flattenSync.
131
+ * @kind function
132
+ * @name flattenAsync
133
+ * @see chainAsync
134
+ */
135
+ export declare function flattenAsync<T>(iterableOfIterables: AsyncIterable<AsyncIterable<T> | Iterable<T>> | Iterable<AsyncIterable<T> | Iterable<T>>): AsyncGenerator<T>;
136
+ /**
137
+ * Cycle through `iterable` forever, buffering it on the first pass so a
138
+ * one-shot source (e.g. a generator) can still be replayed. Yields
139
+ * nothing if the source is empty.
140
+ * @kind function
141
+ * @name cycleSync
142
+ */
143
+ export declare function cycleSync<T>(iterable: Iterable<T>): Generator<T>;
144
+ /**
145
+ * Asynchronous dual of cycleSync.
146
+ * @kind function
147
+ * @name cycleAsync
148
+ */
149
+ export declare function cycleAsync<T>(iterable: AsyncIterable<T> | Iterable<T>): AsyncGenerator<T>;
150
+ /**
151
+ * Yield `value` repeatedly, `times` times (default infinite).
152
+ * @kind function
153
+ * @name repeatSync
154
+ */
155
+ export declare function repeatSync<T>(value: T, times?: number): Generator<T>;
156
+ /**
157
+ * Asynchronous dual of repeatSync.
158
+ * @kind function
159
+ * @name repeatAsync
160
+ */
161
+ export declare function repeatAsync<T>(value: T, times?: number): AsyncGenerator<T>;
162
+ /**
163
+ * Yield only the first occurrence of each key -- global, unbounded-memory
164
+ * dedupe. Mirrors the `unique_everseen` recipe from Python's itertools docs.
165
+ * @kind function
166
+ * @name uniqueSync
167
+ */
168
+ export declare function uniqueSync<T, K = T>(iterable: Iterable<T>, keyFn?: (item: T) => K): Generator<T>;
169
+ /**
170
+ * Asynchronous dual of uniqueSync.
171
+ * @kind function
172
+ * @name uniqueAsync
173
+ */
174
+ export declare function uniqueAsync<T, K = T>(iterable: AsyncIterable<T> | Iterable<T>, keyFn?: (item: T) => K): AsyncGenerator<T>;
175
+ /**
176
+ * Yield `[index, value]` pairs, mirroring Python's builtin enumerate().
177
+ * Implemented via native Iterator Helpers: Iterator.prototype.map's
178
+ * callback receives `(value, index)`, unlike Array.prototype.map's
179
+ * `(value, index, array)` -- confirmed present in ES2025.
180
+ * @kind function
181
+ * @name enumerateSync
182
+ */
183
+ export declare function enumerateSync<T>(iterable: Iterable<T>, start?: number): Generator<[number, T]>;
184
+ /**
185
+ * Asynchronous dual of enumerateSync (hand-rolled -- no native
186
+ * AsyncIterator helpers are shipped yet).
187
+ * @kind function
188
+ * @name enumerateAsync
189
+ */
190
+ export declare function enumerateAsync<T>(iterable: AsyncIterable<T> | Iterable<T>, start?: number): AsyncGenerator<[number, T]>;
191
+ /**
192
+ * Call `fn` with each item's contents spread as arguments. Mirrors
193
+ * Python's itertools.starmap.
194
+ * @kind function
195
+ * @name starmapSync
196
+ */
197
+ export declare function starmapSync<Args extends unknown[], R>(fn: (...args: Args) => R, iterableOfArgArrays: Iterable<Args>): Generator<R>;
198
+ /**
199
+ * Asynchronous dual of starmapSync.
200
+ * @kind function
201
+ * @name starmapAsync
202
+ */
203
+ export declare function starmapAsync<Args extends unknown[], R>(fn: (...args: Args) => R, iterableOfArgArrays: AsyncIterable<Args> | Iterable<Args>): AsyncGenerator<R>;
204
+ /**
205
+ * Zip iterators, continuing to the longest one and filling exhausted
206
+ * ones with `fillValue`. Complement to the strict, stop-at-shortest
207
+ * zipSync/zipAsync. Mirrors Python's itertools.zip_longest.
208
+ * @kind function
209
+ * @name zipLongestSync
210
+ * @param fillValue value used once an input is exhausted
211
+ * @param iteratorList iterables to zip
212
+ */
213
+ export declare function zipLongestSync<T, F>(fillValue: F, ...iteratorList: Array<Iterable<T>>): Generator<Array<T | F>>;
214
+ /**
215
+ * Asynchronous dual of zipLongestSync. Pulls the next value from every
216
+ * input in parallel each round, like zipAsync.
217
+ * @kind function
218
+ * @name zipLongestAsync
219
+ */
220
+ export declare function zipLongestAsync<T, F>(fillValue: F, ...iteratorList: Array<AsyncIterable<T> | Iterable<T>>): AsyncGenerator<Array<T | F>>;
221
+ /**
222
+ * General slicing over an iterable. Mirrors Python's itertools.islice
223
+ * overloads: `isliceSync(iterable, stop)` or
224
+ * `isliceSync(iterable, start, stop, step)`. `step` has no native
225
+ * fast-path, so both sync and async are hand-rolled uniformly rather
226
+ * than branching between a native-composed common case and a fallback.
227
+ * @kind function
228
+ * @name isliceSync
229
+ */
230
+ export declare function isliceSync<T>(iterable: Iterable<T>, ...args: Array<number | null | undefined>): Generator<T>;
231
+ /**
232
+ * Asynchronous dual of isliceSync.
233
+ * @kind function
234
+ * @name isliceAsync
235
+ */
236
+ export declare function isliceAsync<T>(iterable: AsyncIterable<T>, ...args: Array<number | null | undefined>): AsyncGenerator<T>;
237
+ //# sourceMappingURL=itertools.d.ts.map