iter-fest 0.1.1-main.149c8ad → 0.1.1-main.1dec735

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 (177) hide show
  1. package/README.md +50 -90
  2. package/dist/chunk-5CRMPYKD.mjs +19 -0
  3. package/dist/chunk-5CRMPYKD.mjs.map +1 -0
  4. package/dist/chunk-6C3P4TNK.mjs +19 -0
  5. package/dist/chunk-6C3P4TNK.mjs.map +1 -0
  6. package/dist/chunk-EZC33HE6.mjs +15 -0
  7. package/dist/chunk-EZC33HE6.mjs.map +1 -0
  8. package/dist/chunk-JU353VSE.mjs +16 -0
  9. package/dist/chunk-JU353VSE.mjs.map +1 -0
  10. package/dist/chunk-MNLOWKTC.mjs +19 -0
  11. package/dist/chunk-MNLOWKTC.mjs.map +1 -0
  12. package/dist/{chunk-YJSIVBF7.mjs → chunk-MOBXUTO5.mjs} +5 -5
  13. package/dist/chunk-MOBXUTO5.mjs.map +1 -0
  14. package/dist/chunk-O5SQJUKB.mjs +37 -0
  15. package/dist/chunk-O5SQJUKB.mjs.map +1 -0
  16. package/dist/chunk-XW34KZRY.mjs +17 -0
  17. package/dist/chunk-XW34KZRY.mjs.map +1 -0
  18. package/dist/chunk-ZUBHGSCW.mjs +18 -0
  19. package/dist/chunk-ZUBHGSCW.mjs.map +1 -0
  20. package/dist/iter-fest.d.mts +9 -14
  21. package/dist/iter-fest.d.ts +9 -14
  22. package/dist/iter-fest.iterableEvery.d.mts +24 -0
  23. package/dist/iter-fest.iterableEvery.d.ts +24 -0
  24. package/dist/iter-fest.iterableEvery.js +43 -0
  25. package/dist/iter-fest.iterableEvery.js.map +1 -0
  26. package/dist/iter-fest.iterableEvery.mjs +7 -0
  27. package/dist/iter-fest.iterableFilter.d.mts +16 -0
  28. package/dist/iter-fest.iterableFilter.d.ts +16 -0
  29. package/dist/iter-fest.iterableFilter.js +42 -0
  30. package/dist/iter-fest.iterableFilter.js.map +1 -0
  31. package/dist/iter-fest.iterableFilter.mjs +7 -0
  32. package/dist/iter-fest.iterableFind.d.mts +15 -0
  33. package/dist/iter-fest.iterableFind.d.ts +15 -0
  34. package/dist/iter-fest.iterableFind.js +43 -0
  35. package/dist/iter-fest.iterableFind.js.map +1 -0
  36. package/dist/iter-fest.iterableFind.mjs +7 -0
  37. package/dist/iter-fest.iterableForEach.d.mts +10 -0
  38. package/dist/iter-fest.iterableForEach.d.ts +10 -0
  39. package/dist/iter-fest.iterableForEach.js +40 -0
  40. package/dist/iter-fest.iterableForEach.js.map +1 -0
  41. package/dist/iter-fest.iterableForEach.mjs +7 -0
  42. package/dist/iter-fest.iterableGetReadable.d.mts +3 -0
  43. package/dist/iter-fest.iterableGetReadable.d.ts +3 -0
  44. package/dist/{iter-fest.readableStreamFrom.js → iter-fest.iterableGetReadable.js} +9 -9
  45. package/dist/iter-fest.iterableGetReadable.js.map +1 -0
  46. package/dist/iter-fest.iterableGetReadable.mjs +7 -0
  47. package/dist/iter-fest.iterableMap.d.mts +8 -0
  48. package/dist/iter-fest.iterableMap.d.ts +8 -0
  49. package/dist/iter-fest.iterableMap.js +39 -0
  50. package/dist/iter-fest.iterableMap.js.map +1 -0
  51. package/dist/iter-fest.iterableMap.mjs +7 -0
  52. package/dist/{iter-fest.iteratorReduce.d.mts → iter-fest.iterableReduce.d.mts} +9 -13
  53. package/dist/{iter-fest.iteratorReduce.d.ts → iter-fest.iterableReduce.d.ts} +9 -13
  54. package/dist/iter-fest.iterableReduce.js +41 -0
  55. package/dist/iter-fest.iterableReduce.js.map +1 -0
  56. package/dist/iter-fest.iterableReduce.mjs +7 -0
  57. package/dist/iter-fest.iterableSome.d.mts +12 -0
  58. package/dist/iter-fest.iterableSome.d.ts +12 -0
  59. package/dist/iter-fest.iterableSome.js +43 -0
  60. package/dist/iter-fest.iterableSome.js.map +1 -0
  61. package/dist/iter-fest.iterableSome.mjs +7 -0
  62. package/dist/iter-fest.js +168 -164
  63. package/dist/iter-fest.js.map +1 -1
  64. package/dist/iter-fest.mjs +52 -72
  65. package/dist/iter-fest.pushAsyncIterableIterator.d.mts +9 -0
  66. package/dist/iter-fest.pushAsyncIterableIterator.d.ts +9 -0
  67. package/dist/{iter-fest.iterableWritableStream.js → iter-fest.pushAsyncIterableIterator.js} +30 -39
  68. package/dist/iter-fest.pushAsyncIterableIterator.js.map +1 -0
  69. package/dist/iter-fest.pushAsyncIterableIterator.mjs +7 -0
  70. package/package.json +87 -137
  71. package/dist/chunk-3S6LCGE6.mjs +0 -10
  72. package/dist/chunk-3S6LCGE6.mjs.map +0 -1
  73. package/dist/chunk-BWMXKULC.mjs +0 -46
  74. package/dist/chunk-BWMXKULC.mjs.map +0 -1
  75. package/dist/chunk-FBST4AUL.mjs +0 -10
  76. package/dist/chunk-FBST4AUL.mjs.map +0 -1
  77. package/dist/chunk-FMIHIL6A.mjs +0 -10
  78. package/dist/chunk-FMIHIL6A.mjs.map +0 -1
  79. package/dist/chunk-KYMTQJIJ.mjs +0 -10
  80. package/dist/chunk-KYMTQJIJ.mjs.map +0 -1
  81. package/dist/chunk-LIMQXDFK.mjs +0 -10
  82. package/dist/chunk-LIMQXDFK.mjs.map +0 -1
  83. package/dist/chunk-OWUGLCQB.mjs +0 -10
  84. package/dist/chunk-OWUGLCQB.mjs.map +0 -1
  85. package/dist/chunk-QX6EMOSQ.mjs +0 -10
  86. package/dist/chunk-QX6EMOSQ.mjs.map +0 -1
  87. package/dist/chunk-R6SXIXMH.mjs +0 -10
  88. package/dist/chunk-R6SXIXMH.mjs.map +0 -1
  89. package/dist/chunk-TDHR35S7.mjs +0 -10
  90. package/dist/chunk-TDHR35S7.mjs.map +0 -1
  91. package/dist/chunk-VCKLUCOT.mjs +0 -10
  92. package/dist/chunk-VCKLUCOT.mjs.map +0 -1
  93. package/dist/chunk-XQDGXAAF.mjs +0 -10
  94. package/dist/chunk-XQDGXAAF.mjs.map +0 -1
  95. package/dist/chunk-YJSIVBF7.mjs.map +0 -1
  96. package/dist/chunk-YLERARWI.mjs +0 -10
  97. package/dist/chunk-YLERARWI.mjs.map +0 -1
  98. package/dist/iter-fest.iterableWritableStream.d.mts +0 -7
  99. package/dist/iter-fest.iterableWritableStream.d.ts +0 -7
  100. package/dist/iter-fest.iterableWritableStream.js.map +0 -1
  101. package/dist/iter-fest.iterableWritableStream.mjs +0 -7
  102. package/dist/iter-fest.iteratorDrop.d.mts +0 -12
  103. package/dist/iter-fest.iteratorDrop.d.ts +0 -12
  104. package/dist/iter-fest.iteratorDrop.js +0 -44
  105. package/dist/iter-fest.iteratorDrop.js.map +0 -1
  106. package/dist/iter-fest.iteratorDrop.mjs +0 -7
  107. package/dist/iter-fest.iteratorEvery.d.mts +0 -25
  108. package/dist/iter-fest.iteratorEvery.d.ts +0 -25
  109. package/dist/iter-fest.iteratorEvery.js +0 -44
  110. package/dist/iter-fest.iteratorEvery.js.map +0 -1
  111. package/dist/iter-fest.iteratorEvery.mjs +0 -7
  112. package/dist/iter-fest.iteratorFilter.d.mts +0 -18
  113. package/dist/iter-fest.iteratorFilter.d.ts +0 -18
  114. package/dist/iter-fest.iteratorFilter.js +0 -44
  115. package/dist/iter-fest.iteratorFilter.js.map +0 -1
  116. package/dist/iter-fest.iteratorFilter.mjs +0 -7
  117. package/dist/iter-fest.iteratorFind.d.mts +0 -14
  118. package/dist/iter-fest.iteratorFind.d.ts +0 -14
  119. package/dist/iter-fest.iteratorFind.js +0 -44
  120. package/dist/iter-fest.iteratorFind.js.map +0 -1
  121. package/dist/iter-fest.iteratorFind.mjs +0 -7
  122. package/dist/iter-fest.iteratorFlatMap.d.mts +0 -12
  123. package/dist/iter-fest.iteratorFlatMap.d.ts +0 -12
  124. package/dist/iter-fest.iteratorFlatMap.js +0 -44
  125. package/dist/iter-fest.iteratorFlatMap.js.map +0 -1
  126. package/dist/iter-fest.iteratorFlatMap.mjs +0 -7
  127. package/dist/iter-fest.iteratorForEach.d.mts +0 -10
  128. package/dist/iter-fest.iteratorForEach.d.ts +0 -10
  129. package/dist/iter-fest.iteratorForEach.js +0 -44
  130. package/dist/iter-fest.iteratorForEach.js.map +0 -1
  131. package/dist/iter-fest.iteratorForEach.mjs +0 -7
  132. package/dist/iter-fest.iteratorFrom.d.mts +0 -12
  133. package/dist/iter-fest.iteratorFrom.d.ts +0 -12
  134. package/dist/iter-fest.iteratorFrom.js +0 -44
  135. package/dist/iter-fest.iteratorFrom.js.map +0 -1
  136. package/dist/iter-fest.iteratorFrom.mjs +0 -7
  137. package/dist/iter-fest.iteratorMap.d.mts +0 -10
  138. package/dist/iter-fest.iteratorMap.d.ts +0 -10
  139. package/dist/iter-fest.iteratorMap.js +0 -44
  140. package/dist/iter-fest.iteratorMap.js.map +0 -1
  141. package/dist/iter-fest.iteratorMap.mjs +0 -7
  142. package/dist/iter-fest.iteratorReduce.js +0 -44
  143. package/dist/iter-fest.iteratorReduce.js.map +0 -1
  144. package/dist/iter-fest.iteratorReduce.mjs +0 -7
  145. package/dist/iter-fest.iteratorReduce.mjs.map +0 -1
  146. package/dist/iter-fest.iteratorSome.d.mts +0 -10
  147. package/dist/iter-fest.iteratorSome.d.ts +0 -10
  148. package/dist/iter-fest.iteratorSome.js +0 -44
  149. package/dist/iter-fest.iteratorSome.js.map +0 -1
  150. package/dist/iter-fest.iteratorSome.mjs +0 -7
  151. package/dist/iter-fest.iteratorSome.mjs.map +0 -1
  152. package/dist/iter-fest.iteratorTake.d.mts +0 -12
  153. package/dist/iter-fest.iteratorTake.d.ts +0 -12
  154. package/dist/iter-fest.iteratorTake.js +0 -44
  155. package/dist/iter-fest.iteratorTake.js.map +0 -1
  156. package/dist/iter-fest.iteratorTake.mjs +0 -7
  157. package/dist/iter-fest.iteratorTake.mjs.map +0 -1
  158. package/dist/iter-fest.iteratorToArray.d.mts +0 -13
  159. package/dist/iter-fest.iteratorToArray.d.ts +0 -13
  160. package/dist/iter-fest.iteratorToArray.js +0 -44
  161. package/dist/iter-fest.iteratorToArray.js.map +0 -1
  162. package/dist/iter-fest.iteratorToArray.mjs +0 -7
  163. package/dist/iter-fest.iteratorToArray.mjs.map +0 -1
  164. package/dist/iter-fest.readableStreamFrom.d.mts +0 -3
  165. package/dist/iter-fest.readableStreamFrom.d.ts +0 -3
  166. package/dist/iter-fest.readableStreamFrom.js.map +0 -1
  167. package/dist/iter-fest.readableStreamFrom.mjs +0 -7
  168. package/dist/iter-fest.readableStreamFrom.mjs.map +0 -1
  169. /package/dist/{iter-fest.iterableWritableStream.mjs.map → iter-fest.iterableEvery.mjs.map} +0 -0
  170. /package/dist/{iter-fest.iteratorDrop.mjs.map → iter-fest.iterableFilter.mjs.map} +0 -0
  171. /package/dist/{iter-fest.iteratorEvery.mjs.map → iter-fest.iterableFind.mjs.map} +0 -0
  172. /package/dist/{iter-fest.iteratorFilter.mjs.map → iter-fest.iterableForEach.mjs.map} +0 -0
  173. /package/dist/{iter-fest.iteratorFind.mjs.map → iter-fest.iterableGetReadable.mjs.map} +0 -0
  174. /package/dist/{iter-fest.iteratorFlatMap.mjs.map → iter-fest.iterableMap.mjs.map} +0 -0
  175. /package/dist/{iter-fest.iteratorForEach.mjs.map → iter-fest.iterableReduce.mjs.map} +0 -0
  176. /package/dist/{iter-fest.iteratorFrom.mjs.map → iter-fest.iterableSome.mjs.map} +0 -0
  177. /package/dist/{iter-fest.iteratorMap.mjs.map → iter-fest.pushAsyncIterableIterator.mjs.map} +0 -0
package/README.md CHANGED
@@ -16,16 +16,33 @@ Iterables can contains infinite number of items, please use this package respons
16
16
  npm install iter-fest
17
17
  ```
18
18
 
19
+ ### `Array.prototype` ports
20
+
21
+ We ported majority of functions from `Array.prototype.*` to `iterable*`.
22
+
23
+ ```ts
24
+ import { iterableIncludes, iterableReduce } from 'iter-fest'; // Via default exports.
25
+ import { iterableSome } from 'iter-fest/iterableSome'; // Via named exports.
26
+
27
+ const iterable: Iterable<number> = [1, 2, 3, 4, 5].values();
28
+
29
+ console.log(iterableIncludes(iterable, 3)); // Prints "true".
30
+ console.log(iterableReduce(iterable, (sum, value) => sum + value, 0)); // Prints "15".
31
+ console.log(iterableSome(iterable, value => value % 2)); // Prints "true".
32
+ ```
33
+
34
+ List of ported functions: [`at`](https://tc39.es/ecma262/#sec-array.prototype.at), [`concat`](https://tc39.es/ecma262/#sec-array.prototype.concat), [`entries`](https://tc39.es/ecma262/#sec-array.prototype.entries), [`every`](https://tc39.es/ecma262/#sec-array.prototype.every), [`filter`](https://tc39.es/ecma262/#sec-array.prototype.filter), [`find`](https://tc39.es/ecma262/#sec-array.prototype.find), [`findIndex`](https://tc39.es/ecma262/#sec-array.prototype.findindex), [`findLast`](https://tc39.es/ecma262/#sec-array.prototype.findlast), [`findLastIndex`](https://tc39.es/ecma262/#sec-array.prototype.findlastindex), [`forEach`](https://tc39.es/ecma262/#sec-array.prototype.foreach), [`includes`](https://tc39.es/ecma262/#sec-array.prototype.includes), [`indexOf`](https://tc39.es/ecma262/#sec-array.prototype.indexof), [`join`](https://tc39.es/ecma262/#sec-array.prototype.join), [`keys`](https://tc39.es/ecma262/#sec-array.prototype.keys), [`map`](https://tc39.es/ecma262/#sec-array.prototype.map), [`reduce`](https://tc39.es/ecma262/#sec-array.prototype.reduce), [`slice`](https://tc39.es/ecma262/#sec-array.prototype.slice), [`some`](https://tc39.es/ecma262/#sec-array.prototype.some), [`toSpliced`](https://tc39.es/ecma262/#sec-array.prototype.tospliced), and [`toString`](https://tc39.es/ecma262/#sec-array.prototype.tostring).
35
+
19
36
  ## Conversions
20
37
 
21
- | From | To | Function signature |
22
- | ----------------------------- | ----------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------- |
23
- | `Iterator` | `IterableIterator` | [`iteratorToIterable<T>(iterator: Iterator<T>): IterableIterator<T>`](#converting-an-iterator-to-iterable) |
24
- | `AsyncIterator` | `AsyncIterableIterator` | [`asyncIteratorToAsyncIterable<T>(asyncIterator: AsyncIterator<T>): AsyncIterableIterator<T>`](#converting-an-iterator-to-iterable) |
25
- | `Observable` | `ReadableStream` | [`observableSubscribeAsReadable<T>(observable: Observable<T>): ReadableStream<T>`](#converting-an-observable-to-readablestream) |
26
- | `ReadableStreamDefaultReader` | `AsyncIterableIterator` | [`readerValues`<T>(reader: ReadableStreamDefaultReader<T>): AsyncIterableIterator<T>`](#converting-a-readablestreamdefaultreader-to-asynciterableiterator) |
27
- | `AsyncIterable` | `Observable` | [`observableFromAsync<T>(iterable: AsyncIterable<T>): Observable<T>`](#converting-an-asynciterable-to-observable) |
28
- | `AsyncIterable`/`Iterable` | `ReadableStream` | [`readableStreamFrom<T>(anyIterable: AsyncIterable<T> \| Iterable<T>): ReadableStream<T>`](#converting-an-asynciterableiterable-to-readablestream) |
38
+ | From | To | Function signature |
39
+ | ----------------------------- | ----------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------ |
40
+ | `Iterator` | `IterableIterator` | [`iteratorToIterable<T>(iterator: Iterator<T>): IterableIterator<T>`](#converting-an-iterator-to-iterable) |
41
+ | `AsyncIterator` | `AsyncIterableIterator` | [`asyncIteratorToAsyncIterable<T>(asyncIterator: AsyncIterator<T>): AsyncIterableIterator<T>`](#converting-an-iterator-to-iterable) |
42
+ | `Observable` | `ReadableStream` | [`observableSubscribeAsReadable<T>(observable: Observable<T>): ReadableStream<T>`](#converting-an-observable-to-readablestream) |
43
+ | `ReadableStreamDefaultReader` | `AsyncIterableIterator` | [`readerValues`<T>(reader: ReadableStreamDefaultReader<T>): AsyncIterableIterator<T>`](#iterating-readablestreamdefaultreader) |
44
+ | `AsyncIterable` | `Observable` | [`observableFromAsync<T>(iterable: AsyncIterable<T>): Observable<T>`](#converting-an-asynciterable-to-observable) |
45
+ | `AsyncIterable`/`Iterable` | `ReadableStream` | [`iterableGetReadable<T>(iterable: AsyncIterable<T> \| Iterable<T>): ReadableStream<T>`](#converting-an-asynciterableiterable-to-readablestream) |
29
46
 
30
47
  To convert `Observable` to `AsyncIterableIterator`, [use `ReadableStream` as intermediate format](#converting-an-observable-to-asynciterableiterator).
31
48
 
@@ -43,7 +60,7 @@ const iterate = (): Iterator<number> => {
43
60
  return { value };
44
61
  }
45
62
 
46
- return { done: true, value: undefined } satisfies IteratorResult<number>;
63
+ return { done: true, value: undefined };
47
64
  }
48
65
  };
49
66
  };
@@ -53,31 +70,28 @@ for (const value of iteratorToIterable(iterate())) {
53
70
  }
54
71
  ```
55
72
 
56
- Note: calling `[Symbol.iterator]()` or `[Symbol.asyncIterator]()` will not restart the iteration. This is because iterator is an instance of iteration and is not restartable.
73
+ Note: calling `[Symbol.iterator]` will not refresh the iteration.
57
74
 
58
75
  ### Converting an `Observable` to `AsyncIterableIterator`
59
76
 
60
- `ReadableStream` can be used as an intermediate format when converting an `Observable` to `AsyncIterableIterator`.
77
+ `ReadableStream` can be used to when converting an `Observable` to `AsyncIterableIterator`.
61
78
 
62
79
  Note: `Observable` is push-based and it does not support flow control. When converting to `AsyncIterableIteratorrr`, the internal buffer of `ReadableStream` could build up quickly.
63
80
 
64
81
  ```ts
65
82
  const observable = Observable.from([1, 2, 3]);
66
83
  const readable = observableSubscribeAsReadable(observable);
67
- const iterable = readerValues(readable.getReader());
68
84
 
69
- for await (const value of iterable) {
85
+ for await (const value of readerValues(readable.getReader())) {
70
86
  console.log(value); // Prints "1", "2", "3".
71
87
  }
72
88
  ```
73
89
 
74
- Note: calling `[Symbol.asyncIterator]()` will not resubscribe and read from the start of the observable. This is because the intermediate format does not support restart.
75
-
76
90
  ### Converting an `AsyncIterable` to `Observable`
77
91
 
78
92
  `Observable.from` converts `Iterable` into `Observable`. However, it does not convert `AsyncIterable`.
79
93
 
80
- `observableFromAsync` will convert `AsyncIterable` into `Observable`. It will try to restart the iteration by calling `[Symbol.asyncIterator]()`.
94
+ `observableFromAsync` will convert `AsyncIterable` into `Observable`.
81
95
 
82
96
  ```ts
83
97
  async function* generate() {
@@ -92,11 +106,7 @@ const next = value => console.log(value);
92
106
  observable.subscribe({ next }); // Prints "1", "2", "3".
93
107
  ```
94
108
 
95
- Note: `observableFromAsync` will call `[Symbol.asyncIterator]()` initially to restart the iteration where possible.
96
-
97
- Note: It is not recommended to convert `AsyncGenerator` to an `Observable`. `AsyncGenerator` has more functionalities and `Observable` does not support many of them.
98
-
99
- ### Converting an `Observable` to `ReadableStream`
109
+ ## Converting an `Observable` to `ReadableStream`
100
110
 
101
111
  `ReadableStream` is powerful for transforming and piping stream of data. It can be formed using data from both push-based and pull-based source with backpressuree.
102
112
 
@@ -105,11 +115,12 @@ Note: `Observable` is push-based and it does not support flow control. When conv
105
115
  ```ts
106
116
  const observable = Observable.from([1, 2, 3]);
107
117
  const readable = observableSubscribeAsReadable(observable);
118
+ const reader = readable.getReader();
108
119
 
109
120
  readable.pipeTo(stream.writable); // Will write 1, 2, 3.
110
121
  ```
111
122
 
112
- ### Converting a `ReadableStreamDefaultReader` to `AsyncIterableIterator`
123
+ ### Iterating `ReadableStreamDefaultReader`
113
124
 
114
125
  `readerValues` will convert default reader of `ReadableStream` into an `AsyncIterableIterator` to use in for-loop.
115
126
 
@@ -125,28 +136,20 @@ const readableStream = new ReadableStream({
125
136
  }
126
137
  });
127
138
 
128
- const iterable = readerValues(readableStream.getReader());
129
-
130
- for await (const value of iterable) {
139
+ for await (const value of readerValues(readableStream.getReader())) {
131
140
  console.log(value); // Prints "1", "2", "3".
132
141
  }
133
142
  ```
134
143
 
135
- Note: `[Symbol.asyncIterator]()` will not restart the reader and read from start of the stream. Reader is not restartable and streams are not seekable.
136
-
137
- ### Converting an `AsyncIterable`/`Iterable` to `ReadableStream`
138
-
139
- > Notes: this feature is part of [Streams Standard](https://developer.mozilla.org/en-US/docs/Web/API/ReadableStream/from_static).
144
+ ## Converting an `AsyncIterable`/`Iterable` to `ReadableStream`
140
145
 
141
146
  ```ts
142
147
  const iterable = [1, 2, 3].values();
143
- const readable = readableStreamFrom(iterable);
148
+ const readable = iterableGetReadable(iterable);
144
149
 
145
150
  readable.pipeTo(stream.writable); // Will write 1, 2, 3.
146
151
  ```
147
152
 
148
- Note: `readableStreamFrom()` will call `[Symbol.iterator]()` initially to restart the iteration where possible.
149
-
150
153
  ## Others
151
154
 
152
155
  ### Typed `Observable`
@@ -155,18 +158,14 @@ Note: `readableStreamFrom()` will call `[Symbol.iterator]()` initially to restar
155
158
 
156
159
  ### Producer-consumer queue
157
160
 
158
- `IterableWritableStream` is a push-based producer-consumer queue designed to decouple the flow between a producer and multiple consumers. The producer can push a new job at anytime. The consumer can pull a job at its own convenience via for-loop.
161
+ `PushAsyncIterableIterator` is a simple push-based producer-consumer queue and designed to decouple the flow between a producer and consumer. The producer can push a new job at anytime. The consumer can pull a job at its own convenience.
159
162
 
160
- `IterableWritableStream` supports multiple consumers and continuation:
163
+ Compare to pull-based queue, a push-based queue is easier to use. However, pull-based queue offers better flow control as it will produce a job only if there is a consumer ready to consume.
161
164
 
162
- - Multiple consumers: when 2 or more consumers are active at the same time, jobs will be distributed across all consumers in a round robin fashion when possible
163
- - Continuation: when the last consumer disconnected while producer keep pushing new jobs, the next consumer will pick up where the last consumer left
164
-
165
- Compare to pull-based queue, a push-based queue is easy to use. However, pull-based queue offers better flow control as it will produce a job only if there is a consumer ready to consume.
165
+ For a full-featured producer-consumer queue that supports flow control, use `ReadableStream` instead.
166
166
 
167
167
  ```ts
168
- const iterable = new IterableWritableStream();
169
- const writer = iterable.getWriter();
168
+ const iterable = new PushAsyncIterableIterator();
170
169
 
171
170
  (async function consumer() {
172
171
  for await (const value of iterable) {
@@ -177,10 +176,10 @@ const writer = iterable.getWriter();
177
176
  })();
178
177
 
179
178
  (async function producer() {
180
- writer.write(1);
181
- writer.write(2);
182
- writer.write(3);
183
- writer.close();
179
+ iterable.push(1);
180
+ iterable.push(2);
181
+ iterable.push(3);
182
+ iterable.close();
184
183
  })();
185
184
 
186
185
  // Prints "1", "2", "3", "Done".
@@ -197,11 +196,11 @@ The `generatorWithLastValue()` and `asyncGeneratorWithLastValue()` helps bridge
197
196
  ```ts
198
197
  const generator = generatorWithLastValue(
199
198
  (function* () {
200
- yield 1; // { done: false, value: 1 }
201
- yield 2; // { done: false, value: 2 }
202
- yield 3; // { done: false, value: 3 }
199
+ yield 1;
200
+ yield 2;
201
+ yield 3;
203
202
 
204
- return 'end'; // { done: true, value: 'end' }
203
+ return 'end';
205
204
  })()
206
205
  );
207
206
 
@@ -224,42 +223,6 @@ const generator = generatorWithLastValue(
224
223
  );
225
224
  ```
226
225
 
227
- ## Adding types to `core-js-pure`
228
-
229
- We added types to implementation from `core-js-pure`:
230
-
231
- - [`Iterator.drop`](https://tc39.es/ecma262/#sec-array.prototype.drop)
232
- - [`Iterator.every`](https://tc39.es/ecma262/#sec-array.prototype.every)
233
- - [`Iterator.filter`](https://tc39.es/ecma262/#sec-array.prototype.filter)
234
- - [`Iterator.find`](https://tc39.es/ecma262/#sec-array.prototype.find)
235
- - [`Iterator.flatMap`](https://tc39.es/ecma262/#sec-array.prototype.flatmap)
236
- - [`Iterator.forEach`](https://tc39.es/ecma262/#sec-array.prototype.foreach)
237
- - [`Iterator.from`](https://tc39.es/ecma262/#sec-array.prototype.from)
238
- - [`Iterator.map`](https://tc39.es/ecma262/#sec-array.prototype.map)
239
- - [`Iterator.reduce`](https://tc39.es/ecma262/#sec-array.prototype.reduce)
240
- - [`Iterator.some`](https://tc39.es/ecma262/#sec-array.prototype.some)
241
- - [`Iterator.take`](https://tc39.es/ecma262/#sec-array.prototype.take)
242
- - [`Iterator.toArray`](https://tc39.es/ecma262/#sec-array.prototype.toarray)
243
-
244
- ## `Array.prototype` ports
245
-
246
- > Note: we are working to move them from `iterable*` to `iterator*` to make them similar to TC39 proposals.
247
-
248
- We ported majority of functions from `Array.prototype.*` to `iterable*`.
249
-
250
- ```ts
251
- import { iteratorIncludes, iteratorReduce } from 'iter-fest'; // Via default exports.
252
- import { iteratorSome } from 'iter-fest/iteratorSome'; // Via named exports.
253
-
254
- const iterator: iterator<number> = [1, 2, 3, 4, 5].values();
255
-
256
- console.log(iteratorIncludes(iterator, 3)); // Prints "true".
257
- console.log(iteratorReduce(iterator, (sum, value) => sum + value, 0)); // Prints "15".
258
- console.log(iteratorSome(iterator, value => value % 2)); // Prints "true".
259
- ```
260
-
261
- List of ported functions: [`at`](https://tc39.es/ecma262/#sec-array.prototype.at), [`concat`](https://tc39.es/ecma262/#sec-array.prototype.concat), [`entries`](https://tc39.es/ecma262/#sec-array.prototype.entries), [`findIndex`](https://tc39.es/ecma262/#sec-array.prototype.findindex), [`findLast`](https://tc39.es/ecma262/#sec-array.prototype.findlast), [`findLastIndex`](https://tc39.es/ecma262/#sec-array.prototype.findlastindex), [`includes`](https://tc39.es/ecma262/#sec-array.prototype.includes), [`indexOf`](https://tc39.es/ecma262/#sec-array.prototype.indexof), [`join`](https://tc39.es/ecma262/#sec-array.prototype.join), [`keys`](https://tc39.es/ecma262/#sec-array.prototype.keys), [`slice`](https://tc39.es/ecma262/#sec-array.prototype.slice), [`toSpliced`](https://tc39.es/ecma262/#sec-array.prototype.tospliced), and [`toString`](https://tc39.es/ecma262/#sec-array.prototype.tostring).
262
-
263
226
  ## Behaviors
264
227
 
265
228
  ### How this compares to the TC39 proposals?
@@ -308,21 +271,18 @@ Generator has more functionalities than iterator and array. It is not recommende
308
271
  - Generator can define the return value
309
272
  - `return { done: true, value: 'the very last value' }`
310
273
  - Iterating generator using for-loop will not get any values from `{ done: true }`
311
- - The `generatorWithLastValue()` will help capturing and retrieving the last return value
312
274
  - Generator can receive feedback values from its iterator
313
275
  - `generator.next('something')`, the feedback can be assigned to variable via `const feedback = yield;`
314
276
  - For-loop cannot send feedbacks to generator
315
277
 
316
278
  ### When should I use `Iterable`, `IterableIterator` and `Iterator`?
317
279
 
318
- For best compatibility, you should generally follow this API signature: use `Iterable` for inputs, and use `IterableIterator` for outputs. You should avoid exporting pure `Iterator`. Sample function signature should looks below.
280
+ For best compatibility, you should generally follow this API signature: use `Iterable` for inputs, and use `IterableIterator` for outputs. You should avoid exporting pure `Iterator`.
319
281
 
320
282
  ```ts
321
- function myFunction<T>(input: Iterable<T>): IterableIterator<T>;
283
+ function transform<T>(iterable: Iterable<T>): IterableIterator<T>;
322
284
  ```
323
285
 
324
- `IterableIterator` may opt to support restarting the iteration through `[Symbol.iterator]()`. When consuming an `IterableIterator`, you should call `[Symbol.iterator]()` to obtain a fresh iteration or use for-loop statement if possible. However, `[Symbol.iterator]()` is an opt-in feature and does not always guarantee a fresh iteration.
325
-
326
286
  ### What is on the roadmap?
327
287
 
328
288
  We are planning to bring iterables and its siblings together, including:
@@ -0,0 +1,19 @@
1
+ // src/iterableEvery.ts
2
+ function iterableEvery(iterable, predicate, thisArg = void 0) {
3
+ let index = 0;
4
+ if (typeof predicate !== "function") {
5
+ throw new TypeError(`${predicate} is not a function`);
6
+ }
7
+ const boundPredicate = predicate.bind(thisArg);
8
+ for (const value of iterable) {
9
+ if (!boundPredicate(value, index++, iterable)) {
10
+ return false;
11
+ }
12
+ }
13
+ return true;
14
+ }
15
+
16
+ export {
17
+ iterableEvery
18
+ };
19
+ //# sourceMappingURL=chunk-5CRMPYKD.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/iterableEvery.ts"],"sourcesContent":["/**\n * Determines whether all the members of an iterable satisfy the specified test.\n *\n * @param predicate A function that accepts up to three arguments. The every method calls\n * the predicate function for each element in the iterable until the predicate returns a value\n * which is coercible to the Boolean value false, or until the end of the iterable.\n *\n * @param thisArg An object to which the this keyword can refer in the predicate function.\n * If thisArg is omitted, undefined is used as the this value.\n */\nexport function iterableEvery<T, S extends T>(\n iterable: Iterable<T>,\n predicate: (value: T, index: number, iterable: Iterable<T>) => value is S,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n thisArg?: any\n): iterable is S[];\n\n/**\n * Determines whether all the members of an iterable satisfy the specified test.\n *\n * @param predicate A function that accepts up to three arguments. The every method calls\n * the predicate function for each element in the iterable until the predicate returns a value\n * which is coercible to the Boolean value false, or until the end of the iterable.\n *\n * @param thisArg An object to which the this keyword can refer in the predicate function.\n * If thisArg is omitted, undefined is used as the this value.\n */\nexport function iterableEvery<T>(\n iterable: Iterable<T>,\n predicate: (value: T, index: number, iterable: Iterable<T>) => unknown,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n thisArg?: any\n): boolean;\n\nexport function iterableEvery<T>(\n iterable: Iterable<T>,\n predicate: (value: T, index: number, iterable: Iterable<T>) => unknown,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n thisArg: any = undefined\n): boolean {\n let index = 0;\n\n if (typeof predicate !== 'function') {\n throw new TypeError(`${predicate} is not a function`);\n }\n\n const boundPredicate = predicate.bind(thisArg);\n\n for (const value of iterable) {\n if (!boundPredicate(value, index++, iterable)) {\n return false;\n }\n }\n\n return true;\n}\n"],"mappings":";AAkCO,SAAS,cACd,UACA,WAEA,UAAe,QACN;AACT,MAAI,QAAQ;AAEZ,MAAI,OAAO,cAAc,YAAY;AACnC,UAAM,IAAI,UAAU,GAAG,SAAS,oBAAoB;AAAA,EACtD;AAEA,QAAM,iBAAiB,UAAU,KAAK,OAAO;AAE7C,aAAW,SAAS,UAAU;AAC5B,QAAI,CAAC,eAAe,OAAO,SAAS,QAAQ,GAAG;AAC7C,aAAO;AAAA,IACT;AAAA,EACF;AAEA,SAAO;AACT;","names":[]}
@@ -0,0 +1,19 @@
1
+ // src/iterableSome.ts
2
+ function iterableSome(iterable, predicate, thisArg = void 0) {
3
+ let index = 0;
4
+ if (typeof predicate !== "function") {
5
+ throw new TypeError(`${predicate} is not a function`);
6
+ }
7
+ const boundPredicate = predicate.bind(thisArg);
8
+ for (const value of iterable) {
9
+ if (boundPredicate(value, index++, iterable)) {
10
+ return true;
11
+ }
12
+ }
13
+ return false;
14
+ }
15
+
16
+ export {
17
+ iterableSome
18
+ };
19
+ //# sourceMappingURL=chunk-6C3P4TNK.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/iterableSome.ts"],"sourcesContent":["/**\n * Determines whether the specified callback function returns true for any element of an iterable.\n *\n * @param predicate\n * A function that accepts up to three arguments. The some method calls the predicate function for each element in the iterable until the predicate returns a value which is coercible to the Boolean value true, or until the end of the iterable.\n *\n * @param thisArg\n * An object to which the this keyword can refer in the predicate function. If thisArg is omitted, undefined is used as the this value.\n */\nexport function iterableSome<T>(\n iterable: Iterable<T>,\n predicate: (value: T, index: number, iterable: Iterable<T>) => unknown,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n thisArg: any = undefined\n): boolean {\n let index = 0;\n\n if (typeof predicate !== 'function') {\n throw new TypeError(`${predicate} is not a function`);\n }\n\n const boundPredicate = predicate.bind(thisArg);\n\n for (const value of iterable) {\n if (boundPredicate(value, index++, iterable)) {\n return true;\n }\n }\n\n return false;\n}\n"],"mappings":";AASO,SAAS,aACd,UACA,WAEA,UAAe,QACN;AACT,MAAI,QAAQ;AAEZ,MAAI,OAAO,cAAc,YAAY;AACnC,UAAM,IAAI,UAAU,GAAG,SAAS,oBAAoB;AAAA,EACtD;AAEA,QAAM,iBAAiB,UAAU,KAAK,OAAO;AAE7C,aAAW,SAAS,UAAU;AAC5B,QAAI,eAAe,OAAO,SAAS,QAAQ,GAAG;AAC5C,aAAO;AAAA,IACT;AAAA,EACF;AAEA,SAAO;AACT;","names":[]}
@@ -0,0 +1,15 @@
1
+ // src/iterableMap.ts
2
+ function* iterableMap(iterable, callbackfn, thisArg) {
3
+ let index = 0;
4
+ if (typeof callbackfn !== "function") {
5
+ throw new TypeError(`${callbackfn} is not a function`);
6
+ }
7
+ for (const value of iterable) {
8
+ yield callbackfn.call(thisArg, value, index++, iterable);
9
+ }
10
+ }
11
+
12
+ export {
13
+ iterableMap
14
+ };
15
+ //# sourceMappingURL=chunk-EZC33HE6.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/iterableMap.ts"],"sourcesContent":["/**\n * Calls a defined callback function on each element of an array, and returns an array that contains the results.\n * @param callbackfn A function that accepts up to three arguments. The map method calls the callbackfn function one time for each element in the array.\n * @param thisArg An object to which the this keyword can refer in the callbackfn function. If thisArg is omitted, undefined is used as the this value.\n */\nexport function* iterableMap<T, U>(\n iterable: Iterable<T>,\n callbackfn: (value: T, index: number, array: Iterable<T>) => U,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n thisArg?: any\n): IterableIterator<U> {\n let index = 0;\n\n if (typeof callbackfn !== 'function') {\n throw new TypeError(`${callbackfn} is not a function`);\n }\n\n for (const value of iterable) {\n yield callbackfn.call(thisArg, value, index++, iterable);\n }\n}\n"],"mappings":";AAKO,UAAU,YACf,UACA,YAEA,SACqB;AACrB,MAAI,QAAQ;AAEZ,MAAI,OAAO,eAAe,YAAY;AACpC,UAAM,IAAI,UAAU,GAAG,UAAU,oBAAoB;AAAA,EACvD;AAEA,aAAW,SAAS,UAAU;AAC5B,UAAM,WAAW,KAAK,SAAS,OAAO,SAAS,QAAQ;AAAA,EACzD;AACF;","names":[]}
@@ -0,0 +1,16 @@
1
+ // src/iterableForEach.ts
2
+ function iterableForEach(iterable, callbackfn, thisArg) {
3
+ let index = 0;
4
+ if (typeof callbackfn !== "function") {
5
+ throw new TypeError(`${callbackfn} is not a function`);
6
+ }
7
+ const boundCallbackfn = callbackfn.bind(thisArg);
8
+ for (const value of iterable) {
9
+ boundCallbackfn(value, index++, iterable);
10
+ }
11
+ }
12
+
13
+ export {
14
+ iterableForEach
15
+ };
16
+ //# sourceMappingURL=chunk-JU353VSE.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/iterableForEach.ts"],"sourcesContent":["/**\n * Performs the specified action for each element in an iterable.\n *\n * @param callbackfn A function that accepts up to three arguments. forEach calls the callbackfn function one time for each element in the iterable.\n *\n * @param thisArg An object to which the this keyword can refer in the callbackfn function. If thisArg is omitted, undefined is used as the this value.\n */\nexport function iterableForEach<T>(\n iterable: Iterable<T>,\n callbackfn: (value: T, index: number, iterable: Iterable<T>) => void,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n thisArg?: any\n): void {\n let index = 0;\n\n if (typeof callbackfn !== 'function') {\n throw new TypeError(`${callbackfn} is not a function`);\n }\n\n const boundCallbackfn = callbackfn.bind(thisArg);\n\n for (const value of iterable) {\n boundCallbackfn(value, index++, iterable);\n }\n}\n"],"mappings":";AAOO,SAAS,gBACd,UACA,YAEA,SACM;AACN,MAAI,QAAQ;AAEZ,MAAI,OAAO,eAAe,YAAY;AACpC,UAAM,IAAI,UAAU,GAAG,UAAU,oBAAoB;AAAA,EACvD;AAEA,QAAM,kBAAkB,WAAW,KAAK,OAAO;AAE/C,aAAW,SAAS,UAAU;AAC5B,oBAAgB,OAAO,SAAS,QAAQ;AAAA,EAC1C;AACF;","names":[]}
@@ -0,0 +1,19 @@
1
+ // src/iterableFind.ts
2
+ function iterableFind(iterable, predicate, thisArg) {
3
+ let index = 0;
4
+ if (typeof predicate !== "function") {
5
+ throw new TypeError(`${predicate} is not a function`);
6
+ }
7
+ const boundPredicate = predicate.bind(thisArg);
8
+ for (const value of iterable) {
9
+ if (boundPredicate(value, index++, iterable)) {
10
+ return value;
11
+ }
12
+ }
13
+ return void 0;
14
+ }
15
+
16
+ export {
17
+ iterableFind
18
+ };
19
+ //# sourceMappingURL=chunk-MNLOWKTC.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/iterableFind.ts"],"sourcesContent":["/**\n * Returns the value of the first element in the iterable where predicate is true, and undefined\n * otherwise.\n *\n * @param predicate find calls predicate once for each element of the iterable, in ascending\n * order, until it finds one where predicate returns true. If such an element is found, find\n * immediately returns that element value. Otherwise, find returns undefined.\n *\n * @param thisArg If provided, it will be used as the this value for each invocation of\n * predicate. If it is not provided, undefined is used instead.\n */\nexport function iterableFind<T, S extends T>(\n iterable: Iterable<T>,\n predicate: (value: T, index: number, obj: Iterable<T>) => value is S,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n thisArg?: any\n): S | undefined;\n\nexport function iterableFind<T>(\n iterable: Iterable<T>,\n predicate: (value: T, index: number, obj: Iterable<T>) => unknown,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n thisArg?: any\n): T | undefined;\n\nexport function iterableFind<T, S extends T>(\n iterable: Iterable<T>,\n predicate: (value: T, index: number, obj: Iterable<T>) => unknown,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n thisArg?: any\n): S | undefined {\n let index = 0;\n\n if (typeof predicate !== 'function') {\n throw new TypeError(`${predicate} is not a function`);\n }\n\n const boundPredicate = predicate.bind(thisArg);\n\n for (const value of iterable) {\n if (boundPredicate(value, index++, iterable)) {\n return value as S;\n }\n }\n\n return undefined;\n}\n"],"mappings":";AAyBO,SAAS,aACd,UACA,WAEA,SACe;AACf,MAAI,QAAQ;AAEZ,MAAI,OAAO,cAAc,YAAY;AACnC,UAAM,IAAI,UAAU,GAAG,SAAS,oBAAoB;AAAA,EACtD;AAEA,QAAM,iBAAiB,UAAU,KAAK,OAAO;AAE7C,aAAW,SAAS,UAAU;AAC5B,QAAI,eAAe,OAAO,SAAS,QAAQ,GAAG;AAC5C,aAAO;AAAA,IACT;AAAA,EACF;AAEA,SAAO;AACT;","names":[]}
@@ -1,9 +1,9 @@
1
- // src/readableStreamFrom.ts
1
+ // src/iterableGetReadable.ts
2
2
  function isIterable(iterable) {
3
3
  return !!(iterable && typeof iterable === "object" && Symbol.iterator in iterable);
4
4
  }
5
- function readableStreamFrom(anyIterable) {
6
- const iterator = isIterable(anyIterable) ? anyIterable[Symbol.iterator]() : anyIterable[Symbol.asyncIterator]();
5
+ function iterableGetReadable(iterable) {
6
+ const iterator = isIterable(iterable) ? iterable[Symbol.iterator]() : iterable[Symbol.asyncIterator]();
7
7
  return new ReadableStream({
8
8
  async pull(controller) {
9
9
  const result = await iterator.next();
@@ -17,6 +17,6 @@ function readableStreamFrom(anyIterable) {
17
17
  }
18
18
 
19
19
  export {
20
- readableStreamFrom
20
+ iterableGetReadable
21
21
  };
22
- //# sourceMappingURL=chunk-YJSIVBF7.mjs.map
22
+ //# sourceMappingURL=chunk-MOBXUTO5.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/iterableGetReadable.ts"],"sourcesContent":["function isIterable(iterable: unknown): iterable is Iterable<unknown> {\n return !!(iterable && typeof iterable === 'object' && Symbol.iterator in iterable);\n}\n\nexport function iterableGetReadable<T>(iterable: AsyncIterable<T> | Iterable<T>): ReadableStream<T> {\n const iterator = isIterable(iterable) ? iterable[Symbol.iterator]() : iterable[Symbol.asyncIterator]();\n\n return new ReadableStream({\n async pull(controller) {\n const result = await iterator.next();\n\n if (result.done) {\n controller.close();\n } else {\n controller.enqueue(result.value);\n }\n }\n });\n}\n"],"mappings":";AAAA,SAAS,WAAW,UAAkD;AACpE,SAAO,CAAC,EAAE,YAAY,OAAO,aAAa,YAAY,OAAO,YAAY;AAC3E;AAEO,SAAS,oBAAuB,UAA6D;AAClG,QAAM,WAAW,WAAW,QAAQ,IAAI,SAAS,OAAO,QAAQ,EAAE,IAAI,SAAS,OAAO,aAAa,EAAE;AAErG,SAAO,IAAI,eAAe;AAAA,IACxB,MAAM,KAAK,YAAY;AACrB,YAAM,SAAS,MAAM,SAAS,KAAK;AAEnC,UAAI,OAAO,MAAM;AACf,mBAAW,MAAM;AAAA,MACnB,OAAO;AACL,mBAAW,QAAQ,OAAO,KAAK;AAAA,MACjC;AAAA,IACF;AAAA,EACF,CAAC;AACH;","names":[]}
@@ -0,0 +1,37 @@
1
+ // src/private/withResolvers.ts
2
+ import coreJSPromiseWithResolvers from "core-js-pure/full/promise/with-resolvers";
3
+ function withResolvers() {
4
+ return coreJSPromiseWithResolvers();
5
+ }
6
+
7
+ // src/PushAsyncIterableIterator.ts
8
+ var CLOSE = Symbol("close");
9
+ var PushAsyncIterableIterator = class {
10
+ #closed = false;
11
+ #pushResolvers = withResolvers();
12
+ [Symbol.asyncIterator]() {
13
+ return this;
14
+ }
15
+ close() {
16
+ this.#closed = true;
17
+ this.#pushResolvers.resolve(CLOSE);
18
+ }
19
+ async next() {
20
+ const value = await this.#pushResolvers.promise;
21
+ if (value === CLOSE) {
22
+ return { done: true, value: void 0 };
23
+ }
24
+ return { done: false, value };
25
+ }
26
+ push(value) {
27
+ if (!this.#closed) {
28
+ this.#pushResolvers.resolve(value);
29
+ this.#pushResolvers = withResolvers();
30
+ }
31
+ }
32
+ };
33
+
34
+ export {
35
+ PushAsyncIterableIterator
36
+ };
37
+ //# sourceMappingURL=chunk-O5SQJUKB.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/private/withResolvers.ts","../src/PushAsyncIterableIterator.ts"],"sourcesContent":["// @ts-expect-error \"core-js\" is not typed.\nimport coreJSPromiseWithResolvers from 'core-js-pure/full/promise/with-resolvers';\n\nexport default function withResolvers<T>(): PromiseWithResolvers<T> {\n return coreJSPromiseWithResolvers();\n}\n","import withResolvers from './private/withResolvers';\n\nconst CLOSE = Symbol('close');\n\nexport class PushAsyncIterableIterator<T> implements AsyncIterableIterator<T> {\n #closed: boolean = false;\n #pushResolvers: PromiseWithResolvers<T | typeof CLOSE> = withResolvers();\n\n [Symbol.asyncIterator]() {\n return this;\n }\n\n close() {\n this.#closed = true;\n this.#pushResolvers.resolve(CLOSE);\n }\n\n async next(): Promise<IteratorResult<T>> {\n const value = await this.#pushResolvers.promise;\n\n if (value === CLOSE) {\n return { done: true, value: undefined };\n }\n\n return { done: false, value };\n }\n\n push(value: T) {\n if (!this.#closed) {\n this.#pushResolvers.resolve(value);\n this.#pushResolvers = withResolvers();\n }\n }\n}\n"],"mappings":";AACA,OAAO,gCAAgC;AAExB,SAAR,gBAA6D;AAClE,SAAO,2BAA2B;AACpC;;;ACHA,IAAM,QAAQ,OAAO,OAAO;AAErB,IAAM,4BAAN,MAAuE;AAAA,EAC5E,UAAmB;AAAA,EACnB,iBAAyD,cAAc;AAAA,EAEvE,CAAC,OAAO,aAAa,IAAI;AACvB,WAAO;AAAA,EACT;AAAA,EAEA,QAAQ;AACN,SAAK,UAAU;AACf,SAAK,eAAe,QAAQ,KAAK;AAAA,EACnC;AAAA,EAEA,MAAM,OAAmC;AACvC,UAAM,QAAQ,MAAM,KAAK,eAAe;AAExC,QAAI,UAAU,OAAO;AACnB,aAAO,EAAE,MAAM,MAAM,OAAO,OAAU;AAAA,IACxC;AAEA,WAAO,EAAE,MAAM,OAAO,MAAM;AAAA,EAC9B;AAAA,EAEA,KAAK,OAAU;AACb,QAAI,CAAC,KAAK,SAAS;AACjB,WAAK,eAAe,QAAQ,KAAK;AACjC,WAAK,iBAAiB,cAAc;AAAA,IACtC;AAAA,EACF;AACF;","names":[]}
@@ -0,0 +1,17 @@
1
+ // src/iterableReduce.ts
2
+ function iterableReduce(iterable, callbackfn, initialValue) {
3
+ let index = 0;
4
+ let previousValue = initialValue;
5
+ if (typeof callbackfn !== "function") {
6
+ throw new TypeError(`${callbackfn} is not a function`);
7
+ }
8
+ for (const currentValue of iterable) {
9
+ previousValue = callbackfn(previousValue, currentValue, index++, iterable);
10
+ }
11
+ return previousValue;
12
+ }
13
+
14
+ export {
15
+ iterableReduce
16
+ };
17
+ //# sourceMappingURL=chunk-XW34KZRY.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/iterableReduce.ts"],"sourcesContent":["/**\n * Calls the specified callback function for all the elements in an iterable. The return value of the callback function is the accumulated result, and is provided as an argument in the next call to the callback function.\n *\n * @param callbackfn A function that accepts up to four arguments. The reduce method calls the callbackfn function one time for each element in the iterable.\n *\n * @param initialValue If initialValue is specified, it is used as the initial value to start the accumulation. The first call to the callbackfn function provides this value as an argument instead of an iterable value.\n */\nexport function iterableReduce<T>(\n iterable: Iterable<T>,\n callbackfn: (previousValue: T, currentValue: T, currentIndex: number, iterable: Iterable<T>) => T\n): T;\n\nexport function iterableReduce<T>(\n iterable: Iterable<T>,\n callbackfn: (previousValue: T, currentValue: T, currentIndex: number, iterable: Iterable<T>) => T,\n initialValue: T\n): T;\n\n/**\n * Calls the specified callback function for all the elements in an iterable. The return value of the callback function is the accumulated result, and is provided as an argument in the next call to the callback function.\n *\n * @param callbackfn A function that accepts up to four arguments. The reduce method calls the callbackfn function one time for each element in the iterable.\n *\n * @param initialValue If initialValue is specified, it is used as the initial value to start the accumulation. The first call to the callbackfn function provides this value as an argument instead of an array value.\n */\n\nexport function iterableReduce<T, U>(\n iterable: Iterable<T>,\n callbackfn: (previousValue: U, currentValue: T, currentIndex: number, iterable: Iterable<T>) => U,\n initialValue: U\n): U;\n\nexport function iterableReduce<T, U = undefined>(\n iterable: Iterable<T>,\n callbackfn: (previousValue: U | undefined, currentValue: T, currentIndex: number, iterable: Iterable<T>) => U,\n initialValue?: U\n): U | undefined {\n let index = 0;\n let previousValue: U | undefined = initialValue;\n\n if (typeof callbackfn !== 'function') {\n throw new TypeError(`${callbackfn} is not a function`);\n }\n\n for (const currentValue of iterable) {\n previousValue = callbackfn(previousValue, currentValue, index++, iterable);\n }\n\n return previousValue;\n}\n"],"mappings":";AAgCO,SAAS,eACd,UACA,YACA,cACe;AACf,MAAI,QAAQ;AACZ,MAAI,gBAA+B;AAEnC,MAAI,OAAO,eAAe,YAAY;AACpC,UAAM,IAAI,UAAU,GAAG,UAAU,oBAAoB;AAAA,EACvD;AAEA,aAAW,gBAAgB,UAAU;AACnC,oBAAgB,WAAW,eAAe,cAAc,SAAS,QAAQ;AAAA,EAC3E;AAEA,SAAO;AACT;","names":[]}
@@ -0,0 +1,18 @@
1
+ // src/iterableFilter.ts
2
+ function* iterableFilter(iterable, predicate, thisArg) {
3
+ let index = 0;
4
+ if (typeof predicate !== "function") {
5
+ throw new TypeError(`${predicate} is not a function`);
6
+ }
7
+ const boundPredicate = predicate.bind(thisArg);
8
+ for (const value of iterable) {
9
+ if (boundPredicate(value, index++, iterable)) {
10
+ yield value;
11
+ }
12
+ }
13
+ }
14
+
15
+ export {
16
+ iterableFilter
17
+ };
18
+ //# sourceMappingURL=chunk-ZUBHGSCW.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/iterableFilter.ts"],"sourcesContent":["/**\n * Returns the elements of an iterable that meet the condition specified in a callback function.\n *\n * @param predicate A function that accepts up to three arguments. The filter method calls the predicate function one time for each element in the iterable.\n * @param thisArg An object to which the this keyword can refer in the predicate function. If thisArg is omitted, undefined is used as the this value.\n */\nexport function iterableFilter<T, S extends T>(\n iterable: Iterable<T>,\n predicate: (value: T, index: number, iterable: Iterable<T>) => value is S,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n thisArg?: unknown\n): IterableIterator<S>;\n\n/**\n * Returns the elements of an iterable that meet the condition specified in a callback function.\n *\n * @param predicate A function that accepts up to three arguments. The filter method calls the predicate function one time for each element in the iterable.\n * @param thisArg An object to which the this keyword can refer in the predicate function. If thisArg is omitted, undefined is used as the this value.\n */\nexport function iterableFilter<T>(\n iterable: Iterable<T>,\n predicate: (value: T, index: number, iterable: Iterable<T>) => unknown,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n thisArg?: any\n): IterableIterator<T>;\n\nexport function* iterableFilter<T, S extends T>(\n iterable: Iterable<T>,\n predicate: (value: T, index: number, iterable: Iterable<T>) => unknown,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n thisArg?: unknown\n): IterableIterator<S> {\n let index = 0;\n\n if (typeof predicate !== 'function') {\n throw new TypeError(`${predicate} is not a function`);\n }\n\n const boundPredicate = predicate.bind(thisArg);\n\n for (const value of iterable) {\n if (boundPredicate(value, index++, iterable)) {\n yield value as S;\n }\n }\n}\n"],"mappings":";AA0BO,UAAU,eACf,UACA,WAEA,SACqB;AACrB,MAAI,QAAQ;AAEZ,MAAI,OAAO,cAAc,YAAY;AACnC,UAAM,IAAI,UAAU,GAAG,SAAS,oBAAoB;AAAA,EACtD;AAEA,QAAM,iBAAiB,UAAU,KAAK,OAAO;AAE7C,aAAW,SAAS,UAAU;AAC5B,QAAI,eAAe,OAAO,SAAS,QAAQ,GAAG;AAC5C,YAAM;AAAA,IACR;AAAA,EACF;AACF;","names":[]}
@@ -1,4 +1,5 @@
1
1
  export { CompleteFunction, ErrorFunction, NextFunction, Observable, Observer, StartFunction, SubscriberFunction, Subscription, SubscriptionObserver } from './iter-fest.observable.mjs';
2
+ export { PushAsyncIterableIterator } from './iter-fest.pushAsyncIterableIterator.mjs';
2
3
  export { SymbolObservable } from './iter-fest.symbolObservable.mjs';
3
4
  export { AsyncGeneratorWithLastValue, asyncGeneratorWithLastValue } from './iter-fest.asyncGeneratorWithLastValue.mjs';
4
5
  export { asyncIteratorToAsyncIterable } from './iter-fest.asyncIteratorToAsyncIterable.mjs';
@@ -6,32 +7,26 @@ export { GeneratorWithLastValue, generatorWithLastValue } from './iter-fest.gene
6
7
  export { iterableAt } from './iter-fest.iterableAt.mjs';
7
8
  export { iterableConcat } from './iter-fest.iterableConcat.mjs';
8
9
  export { iterableEntries } from './iter-fest.iterableEntries.mjs';
10
+ export { iterableEvery } from './iter-fest.iterableEvery.mjs';
11
+ export { iterableFilter } from './iter-fest.iterableFilter.mjs';
12
+ export { iterableFind } from './iter-fest.iterableFind.mjs';
9
13
  export { iterableFindIndex } from './iter-fest.iterableFindIndex.mjs';
10
14
  export { iterableFindLast } from './iter-fest.iterableFindLast.mjs';
11
15
  export { iterableFindLastIndex } from './iter-fest.iterableFindLastIndex.mjs';
16
+ export { iterableForEach } from './iter-fest.iterableForEach.mjs';
17
+ export { iterableGetReadable } from './iter-fest.iterableGetReadable.mjs';
12
18
  export { iterableIncludes } from './iter-fest.iterableIncludes.mjs';
13
19
  export { iterableIndexOf } from './iter-fest.iterableIndexOf.mjs';
14
20
  export { iterableJoin } from './iter-fest.iterableJoin.mjs';
15
21
  export { iterableKeys } from './iter-fest.iterableKeys.mjs';
22
+ export { iterableMap } from './iter-fest.iterableMap.mjs';
23
+ export { iterableReduce } from './iter-fest.iterableReduce.mjs';
16
24
  export { iterableSlice } from './iter-fest.iterableSlice.mjs';
25
+ export { iterableSome } from './iter-fest.iterableSome.mjs';
17
26
  export { iterableToSpliced } from './iter-fest.iterableToSpliced.mjs';
18
27
  export { iterableToString } from './iter-fest.iterableToString.mjs';
19
- export { IterableWritableStream } from './iter-fest.iterableWritableStream.mjs';
20
- export { iteratorDrop } from './iter-fest.iteratorDrop.mjs';
21
- export { iteratorEvery } from './iter-fest.iteratorEvery.mjs';
22
- export { iteratorFilter } from './iter-fest.iteratorFilter.mjs';
23
- export { iteratorFind } from './iter-fest.iteratorFind.mjs';
24
- export { iteratorFlatMap } from './iter-fest.iteratorFlatMap.mjs';
25
- export { iteratorForEach } from './iter-fest.iteratorForEach.mjs';
26
- export { iteratorFrom } from './iter-fest.iteratorFrom.mjs';
27
- export { iteratorMap } from './iter-fest.iteratorMap.mjs';
28
- export { iteratorReduce } from './iter-fest.iteratorReduce.mjs';
29
- export { iteratorSome } from './iter-fest.iteratorSome.mjs';
30
- export { iteratorTake } from './iter-fest.iteratorTake.mjs';
31
- export { iteratorToArray } from './iter-fest.iteratorToArray.mjs';
32
28
  export { iteratorToIterable } from './iter-fest.iteratorToIterable.mjs';
33
29
  export { observableFromAsync } from './iter-fest.observableFromAsync.mjs';
34
30
  export { observableSubscribeAsReadable } from './iter-fest.observableSubscribeAsReadable.mjs';
35
- export { readableStreamFrom } from './iter-fest.readableStreamFrom.mjs';
36
31
  export { readerValues } from './iter-fest.readerValues.mjs';
37
32
  import 'core-js-pure/full/observable';
@@ -1,4 +1,5 @@
1
1
  export { CompleteFunction, ErrorFunction, NextFunction, Observable, Observer, StartFunction, SubscriberFunction, Subscription, SubscriptionObserver } from './iter-fest.observable.js';
2
+ export { PushAsyncIterableIterator } from './iter-fest.pushAsyncIterableIterator.js';
2
3
  export { SymbolObservable } from './iter-fest.symbolObservable.js';
3
4
  export { AsyncGeneratorWithLastValue, asyncGeneratorWithLastValue } from './iter-fest.asyncGeneratorWithLastValue.js';
4
5
  export { asyncIteratorToAsyncIterable } from './iter-fest.asyncIteratorToAsyncIterable.js';
@@ -6,32 +7,26 @@ export { GeneratorWithLastValue, generatorWithLastValue } from './iter-fest.gene
6
7
  export { iterableAt } from './iter-fest.iterableAt.js';
7
8
  export { iterableConcat } from './iter-fest.iterableConcat.js';
8
9
  export { iterableEntries } from './iter-fest.iterableEntries.js';
10
+ export { iterableEvery } from './iter-fest.iterableEvery.js';
11
+ export { iterableFilter } from './iter-fest.iterableFilter.js';
12
+ export { iterableFind } from './iter-fest.iterableFind.js';
9
13
  export { iterableFindIndex } from './iter-fest.iterableFindIndex.js';
10
14
  export { iterableFindLast } from './iter-fest.iterableFindLast.js';
11
15
  export { iterableFindLastIndex } from './iter-fest.iterableFindLastIndex.js';
16
+ export { iterableForEach } from './iter-fest.iterableForEach.js';
17
+ export { iterableGetReadable } from './iter-fest.iterableGetReadable.js';
12
18
  export { iterableIncludes } from './iter-fest.iterableIncludes.js';
13
19
  export { iterableIndexOf } from './iter-fest.iterableIndexOf.js';
14
20
  export { iterableJoin } from './iter-fest.iterableJoin.js';
15
21
  export { iterableKeys } from './iter-fest.iterableKeys.js';
22
+ export { iterableMap } from './iter-fest.iterableMap.js';
23
+ export { iterableReduce } from './iter-fest.iterableReduce.js';
16
24
  export { iterableSlice } from './iter-fest.iterableSlice.js';
25
+ export { iterableSome } from './iter-fest.iterableSome.js';
17
26
  export { iterableToSpliced } from './iter-fest.iterableToSpliced.js';
18
27
  export { iterableToString } from './iter-fest.iterableToString.js';
19
- export { IterableWritableStream } from './iter-fest.iterableWritableStream.js';
20
- export { iteratorDrop } from './iter-fest.iteratorDrop.js';
21
- export { iteratorEvery } from './iter-fest.iteratorEvery.js';
22
- export { iteratorFilter } from './iter-fest.iteratorFilter.js';
23
- export { iteratorFind } from './iter-fest.iteratorFind.js';
24
- export { iteratorFlatMap } from './iter-fest.iteratorFlatMap.js';
25
- export { iteratorForEach } from './iter-fest.iteratorForEach.js';
26
- export { iteratorFrom } from './iter-fest.iteratorFrom.js';
27
- export { iteratorMap } from './iter-fest.iteratorMap.js';
28
- export { iteratorReduce } from './iter-fest.iteratorReduce.js';
29
- export { iteratorSome } from './iter-fest.iteratorSome.js';
30
- export { iteratorTake } from './iter-fest.iteratorTake.js';
31
- export { iteratorToArray } from './iter-fest.iteratorToArray.js';
32
28
  export { iteratorToIterable } from './iter-fest.iteratorToIterable.js';
33
29
  export { observableFromAsync } from './iter-fest.observableFromAsync.js';
34
30
  export { observableSubscribeAsReadable } from './iter-fest.observableSubscribeAsReadable.js';
35
- export { readableStreamFrom } from './iter-fest.readableStreamFrom.js';
36
31
  export { readerValues } from './iter-fest.readerValues.js';
37
32
  import 'core-js-pure/full/observable';