@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,79 @@
1
+ import { type SignalOptions } from "./abort.ts";
2
+ import { type ReducerStep, type Transducer } from "./iterator-tools.ts";
3
+ /**
4
+ * Transduce -- low-level plumbing kept for protocol experimentation:
5
+ * `reduce(itemCollection, reducer(lastreducer), init)`.
6
+ * @kind function
7
+ * @name transduce
8
+ * @ignore
9
+ */
10
+ export declare const transduce: <Source, Result>(itemCollection: Source, reducer: (last: ReducerStep<never>) => ReducerStep<never>, lastreducer: ReducerStep<never>, init: unknown[], reduce: (itemCollection: Source, step: ReducerStep<never>, init: unknown[]) => Result) => Result;
11
+ /**
12
+ * Create a function that transduces an asynchronous iterator from a list
13
+ * of transducer functions. Transducers compose left to right as written:
14
+ * the first listed transducer sees source items first.
15
+ * @kind function
16
+ * @name transduceAsync
17
+ * @param transducers list of transducers
18
+ * @see transducers
19
+ * @see transduceSync
20
+ * @example <caption>Asynchronously log transduced numbers </caption>
21
+ * ```javascript
22
+ * import { transduceAsync, transducers, countAsync } from '@johnhenry/iteration';
23
+ * const {
24
+ * map,
25
+ * filter,
26
+ * take,
27
+ * } = transducers;
28
+ * const LIMIT = 2 ** 2;
29
+ * const transduce = transduceAsync(
30
+ * filter(x => x % 2),
31
+ * map(x => x + 1),
32
+ * take(LIMIT),
33
+ * );
34
+ * for await (const result of transduce(countAsync(Infinity))) {
35
+ * console.log(result);
36
+ * }
37
+ * ```
38
+ */
39
+ export declare function transduceAsync<A, B>(t1: Transducer<A, B>): (itemCollection: AsyncIterable<A> | Iterable<A>, options?: SignalOptions) => AsyncGenerator<B>;
40
+ export declare function transduceAsync<A, B, C>(t1: Transducer<A, B>, t2: Transducer<B, C>): (itemCollection: AsyncIterable<A> | Iterable<A>, options?: SignalOptions) => AsyncGenerator<C>;
41
+ export declare function transduceAsync<A, B, C, D>(t1: Transducer<A, B>, t2: Transducer<B, C>, t3: Transducer<C, D>): (itemCollection: AsyncIterable<A> | Iterable<A>, options?: SignalOptions) => AsyncGenerator<D>;
42
+ export declare function transduceAsync<A, B, C, D, E>(t1: Transducer<A, B>, t2: Transducer<B, C>, t3: Transducer<C, D>, t4: Transducer<D, E>): (itemCollection: AsyncIterable<A> | Iterable<A>, options?: SignalOptions) => AsyncGenerator<E>;
43
+ export declare function transduceAsync<A, B, C, D, E, F>(t1: Transducer<A, B>, t2: Transducer<B, C>, t3: Transducer<C, D>, t4: Transducer<D, E>, t5: Transducer<E, F>): (itemCollection: AsyncIterable<A> | Iterable<A>, options?: SignalOptions) => AsyncGenerator<F>;
44
+ export declare function transduceAsync(...functions: Array<Transducer<any, any>>): (itemCollection: AsyncIterable<unknown> | Iterable<unknown>, options?: SignalOptions) => AsyncGenerator<unknown>;
45
+ /**
46
+ * Create a function that transduces a synchronous iterator from a list
47
+ * of transducer functions. Transducers compose left to right as written:
48
+ * the first listed transducer sees source items first.
49
+ * @kind function
50
+ * @name transduceSync
51
+ * @param transducers list of transducers
52
+ * @see transducers
53
+ * @see transduceAsync
54
+ * @example <caption>Synchronously log transduced numbers </caption>
55
+ * ```javascript
56
+ * import { transduceSync, transducers, countSync } from '@johnhenry/iteration';
57
+ * const {
58
+ * map,
59
+ * filter,
60
+ * take,
61
+ * } = transducers;
62
+ * const LIMIT = 2 ** 2;
63
+ * const transduce = transduceSync(
64
+ * filter(x => x % 2),
65
+ * map(x => x + 1),
66
+ * take(LIMIT),
67
+ * );
68
+ * for (const result of transduce(countSync(Infinity))) {
69
+ * console.log(result);
70
+ * }
71
+ * ```
72
+ */
73
+ export declare function transduceSync<A, B>(t1: Transducer<A, B>): (itemCollection: Iterable<A>) => Generator<B>;
74
+ export declare function transduceSync<A, B, C>(t1: Transducer<A, B>, t2: Transducer<B, C>): (itemCollection: Iterable<A>) => Generator<C>;
75
+ export declare function transduceSync<A, B, C, D>(t1: Transducer<A, B>, t2: Transducer<B, C>, t3: Transducer<C, D>): (itemCollection: Iterable<A>) => Generator<D>;
76
+ export declare function transduceSync<A, B, C, D, E>(t1: Transducer<A, B>, t2: Transducer<B, C>, t3: Transducer<C, D>, t4: Transducer<D, E>): (itemCollection: Iterable<A>) => Generator<E>;
77
+ export declare function transduceSync<A, B, C, D, E, F>(t1: Transducer<A, B>, t2: Transducer<B, C>, t3: Transducer<C, D>, t4: Transducer<D, E>, t5: Transducer<E, F>): (itemCollection: Iterable<A>) => Generator<F>;
78
+ export declare function transduceSync(...functions: Array<Transducer<any, any>>): (itemCollection: Iterable<unknown>) => Generator<unknown>;
79
+ //# sourceMappingURL=transduce.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transduce.d.ts","sourceRoot":"","sources":["../src/transduce.ts"],"names":[],"mappings":"AAAA,OAAO,EAAa,KAAK,aAAa,EAAE,MAAM,YAAY,CAAC;AAC3D,OAAO,EAAE,KAAK,WAAW,EAA2B,KAAK,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAgBjG;;;;;;GAMG;AACH,eAAO,MAAM,SAAS,GAAI,MAAM,EAAE,MAAM,EACtC,gBAAgB,MAAM,EACtB,SAAS,CAAC,IAAI,EAAE,WAAW,CAAC,KAAK,CAAC,KAAK,WAAW,CAAC,KAAK,CAAC,EACzD,aAAa,WAAW,CAAC,KAAK,CAAC,EAC/B,MAAM,OAAO,EAAE,EACf,QAAQ,CAAC,cAAc,EAAE,MAAM,EAAE,IAAI,EAAE,WAAW,CAAC,KAAK,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,MAAM,KACpF,MAA4D,CAAC;AAahE;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,wBAAgB,cAAc,CAAC,CAAC,EAAE,CAAC,EACjC,EAAE,EAAE,UAAU,CAAC,CAAC,EAAE,CAAC,CAAC,GACnB,CAAC,cAAc,EAAE,aAAa,CAAC,CAAC,CAAC,GAAG,QAAQ,CAAC,CAAC,CAAC,EAAE,OAAO,CAAC,EAAE,aAAa,KAAK,cAAc,CAAC,CAAC,CAAC,CAAC;AAClG,wBAAgB,cAAc,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EACpC,EAAE,EAAE,UAAU,CAAC,CAAC,EAAE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+ * The innermost reducer step ("emit"): pushes an emitted item onto the
5
+ * pending-emission buffer (the accumulator) and returns the buffer.
6
+ * Replaces the v2.0 innermost step (conjoinSync/conjoinAsync), which
7
+ * wrapped the previous accumulator in a fresh generator per item --
8
+ * forming an ever-growing generator chain and leaking ~176 bytes per item
9
+ * on long streams. See reduceSync (iterator-tools.ts) for the full
10
+ * protocol description.
11
+ */
12
+ const emit = (buffer, item) => {
13
+ buffer.push(item);
14
+ return buffer;
15
+ };
16
+ /**
17
+ * Transduce -- low-level plumbing kept for protocol experimentation:
18
+ * `reduce(itemCollection, reducer(lastreducer), init)`.
19
+ * @kind function
20
+ * @name transduce
21
+ * @ignore
22
+ */
23
+ export const transduce = (itemCollection, reducer, lastreducer, init, reduce) => reduce(itemCollection, reducer(lastreducer), init);
24
+ /**
25
+ * Compose Functions
26
+ * @kind function
27
+ * @name composeFunctions
28
+ * @ignore
29
+ */
30
+ const composeFunctions = (...functions) => (input) => functions.reduceRight((input, func) => func(input), input);
31
+ export function transduceAsync(...functions) {
32
+ return (itemCollection, { signal } = {}) => reduceAsync(signal ? abortable(itemCollection, signal) : itemCollection, composeFunctions(...functions)(emit), []);
33
+ }
34
+ export function transduceSync(...functions) {
35
+ return (itemCollection) => reduceSync(itemCollection, composeFunctions(...functions)(emit), []);
36
+ }
37
+ //# sourceMappingURL=transduce.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transduce.js","sourceRoot":"","sources":["../src/transduce.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAsB,MAAM,YAAY,CAAC;AAC3D,OAAO,EAAoB,WAAW,EAAE,UAAU,EAAmB,MAAM,qBAAqB,CAAC;AAEjG;;;;;;;;GAQG;AACH,MAAM,IAAI,GAAyB,CAAC,MAAM,EAAE,IAAI,EAAE,EAAE;IAClD,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAClB,OAAO,MAAM,CAAC;AAChB,CAAC,CAAC;AAEF;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,SAAS,GAAG,CACvB,cAAsB,EACtB,OAAyD,EACzD,WAA+B,EAC/B,IAAe,EACf,MAAqF,EAC7E,EAAE,CAAC,MAAM,CAAC,cAAc,EAAE,OAAO,CAAC,WAAW,CAAC,EAAE,IAAI,CAAC,CAAC;AAEhE;;;;;GAKG;AACH,MAAM,gBAAgB,GACpB,CAAC,GAAG,SAA8C,EAAE,EAAE,CACtD,CAAC,KAA2B,EAAwB,EAAE,CACpD,SAAS,CAAC,WAAW,CAAC,CAAC,KAAK,EAAE,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,KAAK,CAAC,CAAC;AA0D/D,MAAM,UAAU,cAAc,CAAC,GAAG,SAAsC;IACtE,OAAO,CAAC,cAA0D,EAAE,EAAE,MAAM,KAAoB,EAAE,EAAE,EAAE,CACpG,WAAW,CAAC,MAAM,CAAC,CAAC,CAAC,SAAS,CAAC,cAAc,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC,cAAc,EAAE,gBAAgB,CAAC,GAAG,SAAS,CAAC,CAAC,IAAI,CAAC,EAAE,EAAE,CAAC,CAAC;AACvH,CAAC;AAwDD,MAAM,UAAU,aAAa,CAAC,GAAG,SAAsC;IACrE,OAAO,CAAC,cAAiC,EAAE,EAAE,CAAC,UAAU,CAAC,cAAc,EAAE,gBAAgB,CAAC,GAAG,SAAS,CAAC,CAAC,IAAI,CAAC,EAAE,EAAE,CAAC,CAAC;AACrH,CAAC"}
@@ -0,0 +1,123 @@
1
+ /**
2
+ * Functions that return transducers
3
+ * @kind namespace
4
+ * @name transducerReturners
5
+ * @see transduceSync
6
+ * @see transduceAsync
7
+ */
8
+ import { type Transducer } from "./iterator-tools.ts";
9
+ /**
10
+ * Create a transducer that maps values
11
+ * @kind function
12
+ * @name map
13
+ * @param transform transformation function applied to each item
14
+ * @returns transducer
15
+ */
16
+ export declare const map: <In, Out>(transform: (item: In) => Out) => Transducer<In, Out>;
17
+ /**
18
+ * Create a transducer that filters values
19
+ * @kind function
20
+ * @name filter
21
+ * @param predicate boolean function to determine if an item is emitted
22
+ * @returns transducer
23
+ */
24
+ export declare const filter: <In>(predicate: (item: In) => boolean) => Transducer<In, In>;
25
+ /**
26
+ * Create a transducer that halts after a given number of values
27
+ * @kind function
28
+ * @name take
29
+ * @param limit maximum total items to emit
30
+ * @returns transducer
31
+ */
32
+ export declare const take: <In>(limit: number) => Transducer<In, In>;
33
+ /**
34
+ * Create a transducer that drops the first N values
35
+ * before begining to yield
36
+ * @kind function
37
+ * @name drop
38
+ * @param limit number of leading items to drop
39
+ * @returns transducer
40
+ * @see reject
41
+ */
42
+ export declare const drop: <In>(limit: number) => Transducer<In, In>;
43
+ /**
44
+ * Create a transducer that rejects values matching a predicate.
45
+ * The complement of `filter`.
46
+ * @kind function
47
+ * @name reject
48
+ * @param predicate boolean function; matching items are dropped
49
+ * @returns transducer
50
+ * @see filter
51
+ * @see drop
52
+ */
53
+ export declare const reject: <In>(predicate: (item: In) => boolean) => Transducer<In, In>;
54
+ /**
55
+ * Create a transducer that groups items by quantity before emitting.
56
+ * Note: this currently returns arrays -- would sets make more sense?
57
+ * Any trailing items that don't fill a complete group are flushed as a
58
+ * final, shorter group when the source iterator completes (see the
59
+ * `.complete` transducer protocol in transduce.ts/iterator-tools.ts).
60
+ * @kind function
61
+ * @name group
62
+ * @param limit size of group
63
+ * @returns transducer
64
+ */
65
+ export declare const group: <In>(limit: number) => Transducer<In, In[]>;
66
+ /**
67
+ * Create a transducer that accumulates items into a result and emits them
68
+ * Similar to #Array.reduce
69
+ * @kind function
70
+ * @name accumulate
71
+ * @param func accumulation function
72
+ * @param initial initial accumulation value
73
+ * @returns transducer
74
+ */
75
+ export declare const accumulate: <In, Acc = In>(func?: (accumulated: Acc, item: In) => Acc, initial?: Acc) => Transducer<In, Acc>;
76
+ /**
77
+ * Create a transducer that skips consecutive duplicate items (by key).
78
+ * Mirrors the `unique_justseen` recipe documented in Python's itertools
79
+ * docs -- the transducer-pipeline, adjacent-only counterpart to
80
+ * itertools.ts's global, unbounded-memory uniqueSync/uniqueAsync.
81
+ * @kind function
82
+ * @name dedupe
83
+ * @param keyFn maps an item to the key duplicates are compared by
84
+ * @returns transducer
85
+ * @see uniqueSync
86
+ */
87
+ export declare const dedupe: <In>(keyFn?: (item: In) => unknown) => Transducer<In, In>;
88
+ /**
89
+ * Create a transducer that inserts `separator` between consecutive
90
+ * emitted items -- not before the first item, and not after the last.
91
+ * @kind function
92
+ * @name interpose
93
+ * @param separator value inserted between items
94
+ * @returns transducer
95
+ */
96
+ export declare const interpose: <In, Sep = In>(separator: Sep) => Transducer<In, In | Sep>;
97
+ /**
98
+ * Create a transducer that groups consecutive items sharing a key into
99
+ * arrays, emitting each completed group as soon as the key changes.
100
+ * The transducer-pipeline counterpart to groupBySync/groupByAsync
101
+ * (itertools.ts); distinct from `group`, above, which chunks by a fixed
102
+ * size rather than by a shared key. Any trailing group is flushed when the
103
+ * source iterator completes, following the same `.complete` protocol as
104
+ * `group`.
105
+ * @kind function
106
+ * @name partitionBy
107
+ * @param keyFn maps an item to the key runs are grouped by
108
+ * @returns transducer
109
+ * @see groupBySync
110
+ * @see group
111
+ */
112
+ export declare const partitionBy: <In>(keyFn?: (item: In) => unknown) => Transducer<In, In[]>;
113
+ /**
114
+ * Create a transducer that calls `fn(item)` for its side effect and passes
115
+ * the item through unchanged. RxJS-style, for debugging/instrumenting a
116
+ * pipeline without altering its values.
117
+ * @kind function
118
+ * @name tap
119
+ * @param fn called with each item, for side effects
120
+ * @returns transducer
121
+ */
122
+ export declare const tap: <In>(fn: (item: In) => unknown) => Transducer<In, In>;
123
+ //# sourceMappingURL=transducers.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transducers.d.ts","sourceRoot":"","sources":["../src/transducers.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAA0B,KAAK,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAE9E;;;;;;GAMG;AAC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M,SAAS,GACnB,EAAE,EAAE,GAAG,GAAG,EAAE,EAAE,WAAW,GAAG,KAAG,UAAU,CAAC,EAAE,EAAE,EAAE,GAAG,GAAG,CActD,CAAC;AAEJ;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,WAAW,GACrB,EAAE,EAAE,QAAO,CAAC,IAAI,EAAE,EAAE,KAAK,OAAkB,KAAG,UAAU,CAAC,EAAE,EAAE,EAAE,EAAE,CA4BjE,CAAC;AAEJ;;;;;;;;GAQG;AACH,eAAO,MAAM,GAAG,GACb,EAAE,EAAE,IAAI,CAAC,IAAI,EAAE,EAAE,KAAK,OAAO,KAAG,UAAU,CAAC,EAAE,EAAE,EAAE,CAKjD,CAAC"}
@@ -0,0 +1,212 @@
1
+ /**
2
+ * Functions that return transducers
3
+ * @kind namespace
4
+ * @name transducerReturners
5
+ * @see transduceSync
6
+ * @see transduceAsync
7
+ */
8
+ import { HALT } from "./iterator-tools.js";
9
+ /**
10
+ * Create a transducer that maps values
11
+ * @kind function
12
+ * @name map
13
+ * @param transform transformation function applied to each item
14
+ * @returns transducer
15
+ */
16
+ export const map = (transform) => (conjoin) => (init, item) => conjoin(init, transform(item));
17
+ /**
18
+ * Create a transducer that filters values
19
+ * @kind function
20
+ * @name filter
21
+ * @param predicate boolean function to determine if an item is emitted
22
+ * @returns transducer
23
+ */
24
+ export const filter = (predicate) => (conjoin) => (init, item) => predicate(item) ? conjoin(init, item) : init;
25
+ /**
26
+ * Create a transducer that halts after a given number of values
27
+ * @kind function
28
+ * @name take
29
+ * @param limit maximum total items to emit
30
+ * @returns transducer
31
+ */
32
+ export const take = (limit) => (conjoin) => {
33
+ let amount = 0;
34
+ // biome-ignore lint/complexity/noCommaOperator: deliberate single-expression step function
35
+ return (init, item) => (amount < limit ? (amount++, conjoin(init, item)) : HALT);
36
+ };
37
+ /**
38
+ * Create a transducer that drops the first N values
39
+ * before begining to yield
40
+ * @kind function
41
+ * @name drop
42
+ * @param limit number of leading items to drop
43
+ * @returns transducer
44
+ * @see reject
45
+ */
46
+ export const drop = (limit) => (conjoin) => {
47
+ let amount = 0;
48
+ // biome-ignore lint/complexity/noCommaOperator: deliberate single-expression step function
49
+ return (init, item) => (amount >= limit ? (amount++, conjoin(init, item)) : (amount++, init));
50
+ };
51
+ /**
52
+ * Create a transducer that rejects values matching a predicate.
53
+ * The complement of `filter`.
54
+ * @kind function
55
+ * @name reject
56
+ * @param predicate boolean function; matching items are dropped
57
+ * @returns transducer
58
+ * @see filter
59
+ * @see drop
60
+ */
61
+ export const reject = (predicate) => (conjoin) => (init, item) => predicate(item) ? init : conjoin(init, item);
62
+ /**
63
+ * Create a transducer that groups items by quantity before emitting.
64
+ * Note: this currently returns arrays -- would sets make more sense?
65
+ * Any trailing items that don't fill a complete group are flushed as a
66
+ * final, shorter group when the source iterator completes (see the
67
+ * `.complete` transducer protocol in transduce.ts/iterator-tools.ts).
68
+ * @kind function
69
+ * @name group
70
+ * @param limit size of group
71
+ * @returns transducer
72
+ */
73
+ export const group = (limit) => (conjoin) => {
74
+ const partition = [];
75
+ const step = (init, item) => {
76
+ partition.push(item);
77
+ if (partition.length === limit) {
78
+ return conjoin(init, partition.splice(0, limit));
79
+ }
80
+ return init;
81
+ };
82
+ step.complete = (init) => {
83
+ const out = partition.length > 0 ? conjoin(init, partition.splice(0)) : init;
84
+ const buffer = out === HALT ? init : out;
85
+ return conjoin.complete ? conjoin.complete(buffer) : buffer;
86
+ };
87
+ return step;
88
+ };
89
+ /**
90
+ * Create a transducer that accumulates items into a result and emits them
91
+ * Similar to #Array.reduce
92
+ * @kind function
93
+ * @name accumulate
94
+ * @param func accumulation function
95
+ * @param initial initial accumulation value
96
+ * @returns transducer
97
+ */
98
+ export const accumulate = (func = (a, b) => (a + b), initial = 0) => (conjoin) => {
99
+ // Fresh per (conjoin) invocation -- i.e. per transduce run, matching
100
+ // every other stateful transducer in this file (take's `amount`,
101
+ // group's `partition`, etc). Mutating the outer `initial` parameter
102
+ // directly here would carry accumulated state over into the *next*
103
+ // transduce run that reuses this same accumulate(...) instance.
104
+ let accumulated = initial;
105
+ return (init, item) => {
106
+ accumulated = func(accumulated, item);
107
+ return conjoin(init, accumulated);
108
+ };
109
+ };
110
+ /**
111
+ * Create a transducer that skips consecutive duplicate items (by key).
112
+ * Mirrors the `unique_justseen` recipe documented in Python's itertools
113
+ * docs -- the transducer-pipeline, adjacent-only counterpart to
114
+ * itertools.ts's global, unbounded-memory uniqueSync/uniqueAsync.
115
+ * @kind function
116
+ * @name dedupe
117
+ * @param keyFn maps an item to the key duplicates are compared by
118
+ * @returns transducer
119
+ * @see uniqueSync
120
+ */
121
+ export const dedupe = (keyFn = (x) => x) => (conjoin) => {
122
+ let hasLast = false;
123
+ let lastKey;
124
+ return (init, item) => {
125
+ const key = keyFn(item);
126
+ if (hasLast && Object.is(key, lastKey)) {
127
+ return init;
128
+ }
129
+ hasLast = true;
130
+ lastKey = key;
131
+ return conjoin(init, item);
132
+ };
133
+ };
134
+ /**
135
+ * Create a transducer that inserts `separator` between consecutive
136
+ * emitted items -- not before the first item, and not after the last.
137
+ * @kind function
138
+ * @name interpose
139
+ * @param separator value inserted between items
140
+ * @returns transducer
141
+ */
142
+ export const interpose = (separator) => (conjoin) => {
143
+ let started = false;
144
+ return (init, item) => {
145
+ if (started) {
146
+ const out = conjoin(init, separator);
147
+ if (out === HALT) {
148
+ return HALT;
149
+ }
150
+ init = out;
151
+ }
152
+ started = true;
153
+ return conjoin(init, item);
154
+ };
155
+ };
156
+ /**
157
+ * Create a transducer that groups consecutive items sharing a key into
158
+ * arrays, emitting each completed group as soon as the key changes.
159
+ * The transducer-pipeline counterpart to groupBySync/groupByAsync
160
+ * (itertools.ts); distinct from `group`, above, which chunks by a fixed
161
+ * size rather than by a shared key. Any trailing group is flushed when the
162
+ * source iterator completes, following the same `.complete` protocol as
163
+ * `group`.
164
+ * @kind function
165
+ * @name partitionBy
166
+ * @param keyFn maps an item to the key runs are grouped by
167
+ * @returns transducer
168
+ * @see groupBySync
169
+ * @see group
170
+ */
171
+ export const partitionBy = (keyFn = (x) => x) => (conjoin) => {
172
+ let hasCurrent = false;
173
+ let currentKey;
174
+ let bucket = [];
175
+ const step = (init, item) => {
176
+ const key = keyFn(item);
177
+ if (!hasCurrent) {
178
+ hasCurrent = true;
179
+ currentKey = key;
180
+ bucket = [item];
181
+ return init;
182
+ }
183
+ if (Object.is(key, currentKey)) {
184
+ bucket.push(item);
185
+ return init;
186
+ }
187
+ const out = conjoin(init, bucket);
188
+ currentKey = key;
189
+ bucket = [item];
190
+ return out;
191
+ };
192
+ step.complete = (init) => {
193
+ const out = bucket.length > 0 ? conjoin(init, bucket) : init;
194
+ const buffer = out === HALT ? init : out;
195
+ return conjoin.complete ? conjoin.complete(buffer) : buffer;
196
+ };
197
+ return step;
198
+ };
199
+ /**
200
+ * Create a transducer that calls `fn(item)` for its side effect and passes
201
+ * the item through unchanged. RxJS-style, for debugging/instrumenting a
202
+ * pipeline without altering its values.
203
+ * @kind function
204
+ * @name tap
205
+ * @param fn called with each item, for side effects
206
+ * @returns transducer
207
+ */
208
+ export const tap = (fn) => (conjoin) => (init, item) => {
209
+ fn(item);
210
+ return conjoin(init, item);
211
+ };
212
+ //# sourceMappingURL=transducers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transducers.js","sourceRoot":"","sources":["../src/transducers.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,IAAI,EAAqC,MAAM,qBAAqB,CAAC;AAE9E;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,GAAG,GACd,CAAU,SAA4B,EAAuB,EAAE,CAC/D,CAAC,OAAO,EAAE,EAAE,CACZ,CAAC,IAAI,EAAE,IAAI,EAAE,EAAE,CACb,OAAO,CAAC,IAAI,EAAE,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC;AAEnC;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,MAAM,GACjB,CAAK,SAAgC,EAAsB,EAAE,CAC7D,C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C,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,CAAC;QACzC,OAAO,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC;IAC9D,CAAC,CAAC;IACF,OAAO,IAAI,CAAC;AACd,CAAC,CAAC;AAEJ;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,GAAG,GACd,CAAK,EAAyB,EAAsB,EAAE,CACtD,CAAC,OAAO,EAAE,EAAE,CACZ,CAAC,IAAI,EAAE,IAAI,EAAE,EAAE;IACb,EAAE,CAAC,IAAI,CAAC,CAAC;IACT,OAAO,OAAO,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;AAC7B,CAAC,CAAC"}
package/package.json ADDED
@@ -0,0 +1,122 @@
1
+ {
2
+ "name": "@johnhenry/iteration",
3
+ "type": "module",
4
+ "publishConfig": {
5
+ "access": "public",
6
+ "provenance": true
7
+ },
8
+ "engines": {
9
+ "node": ">=22.12.0",
10
+ "npm": ">=8.19.2"
11
+ },
12
+ "exports": {
13
+ ".": {
14
+ "types": "./dist/index.d.ts",
15
+ "import": "./dist/index.js"
16
+ },
17
+ "./pop-quiz/asserteventualequal": {
18
+ "types": "./dist/assertions/eventualequal.d.ts",
19
+ "import": "./dist/assertions/eventualequal.js"
20
+ },
21
+ "./tee": {
22
+ "types": "./dist/tee.d.ts",
23
+ "import": "./dist/tee.js"
24
+ },
25
+ "./transduce": {
26
+ "types": "./dist/transduce.d.ts",
27
+ "import": "./dist/transduce.js"
28
+ },
29
+ "./transducers": {
30
+ "types": "./dist/transducers.d.ts",
31
+ "import": "./dist/transducers.js"
32
+ },
33
+ "./iterator-tools": {
34
+ "types": "./dist/iterator-tools.d.ts",
35
+ "import": "./dist/iterator-tools.js"
36
+ },
37
+ "./itertools": {
38
+ "types": "./dist/itertools.d.ts",
39
+ "import": "./dist/itertools.js"
40
+ },
41
+ "./consumers": {
42
+ "types": "./dist/consumers.d.ts",
43
+ "import": "./dist/consumers.js"
44
+ },
45
+ "./empty-iterator": {
46
+ "types": "./dist/empty-iterator.d.ts",
47
+ "import": "./dist/empty-iterator.js"
48
+ },
49
+ "./channel-decorators": {
50
+ "types": "./dist/channel-decorators.d.ts",
51
+ "import": "./dist/channel-decorators.js"
52
+ },
53
+ "./async-channel": {
54
+ "types": "./dist/async-channel.d.ts",
55
+ "import": "./dist/async-channel.js"
56
+ },
57
+ "./abort": {
58
+ "types": "./dist/abort.d.ts",
59
+ "import": "./dist/abort.js"
60
+ },
61
+ "./concurrency": {
62
+ "types": "./dist/concurrency.d.ts",
63
+ "import": "./dist/concurrency.js"
64
+ },
65
+ "./count": {
66
+ "types": "./dist/count.d.ts",
67
+ "import": "./dist/count.js"
68
+ },
69
+ "./exhaust": {
70
+ "types": "./dist/exhaust.d.ts",
71
+ "import": "./dist/exhaust.js"
72
+ },
73
+ "./is-iterator": {
74
+ "types": "./dist/is-iterator.d.ts",
75
+ "import": "./dist/is-iterator.js"
76
+ }
77
+ },
78
+ "repository": {
79
+ "type": "git",
80
+ "url": "git+https://github.com/johnhenry/math.git",
81
+ "directory": "packages/iteration"
82
+ },
83
+ "version": "0.0.0",
84
+ "description": "Sync + async iterator algebra for TypeScript — transducers, Python-itertools parity, terminal consumers, bounded concurrency, cancellation, and backpressure-aware channels. Zero runtime dependencies.",
85
+ "main": "./dist/index.js",
86
+ "types": "./dist/index.d.ts",
87
+ "files": [
88
+ "dist",
89
+ "src",
90
+ "readme.md",
91
+ "MIT-LICENSE.txt"
92
+ ],
93
+ "directories": {
94
+ "example": "example"
95
+ },
96
+ "scripts": {
97
+ "build": "tsc -p tsconfig.json",
98
+ "typecheck": "tsc -p tsconfig.json --noEmit",
99
+ "prepare": "npm run build",
100
+ "test": "node --test --expose-gc --experimental-strip-types \"test/**/*.test.ts\"",
101
+ "test:build": "npm run build && node scripts/dist-smoke-test.mjs && node scripts/require-esm-smoke-test.cjs"
102
+ },
103
+ "keywords": [
104
+ "async",
105
+ "iterator",
106
+ "iterable",
107
+ "itertools",
108
+ "transducer",
109
+ "channel",
110
+ "generator",
111
+ "tee",
112
+ "zip",
113
+ "python",
114
+ "typescript"
115
+ ],
116
+ "author": "John Henry",
117
+ "license": "MIT",
118
+ "devDependencies": {
119
+ "@types/node": "^22.10.0",
120
+ "typescript": "^5.9.0"
121
+ }
122
+ }