iter-fest 0.1.1-main.dd552c2 → 0.1.1-main.edf2470
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +50 -91
- package/dist/chunk-5CRMPYKD.mjs +19 -0
- package/dist/chunk-5CRMPYKD.mjs.map +1 -0
- package/dist/chunk-6C3P4TNK.mjs +19 -0
- package/dist/chunk-6C3P4TNK.mjs.map +1 -0
- package/dist/chunk-EZC33HE6.mjs +15 -0
- package/dist/chunk-EZC33HE6.mjs.map +1 -0
- package/dist/chunk-JU353VSE.mjs +16 -0
- package/dist/chunk-JU353VSE.mjs.map +1 -0
- package/dist/chunk-MNLOWKTC.mjs +19 -0
- package/dist/chunk-MNLOWKTC.mjs.map +1 -0
- package/dist/{chunk-YJSIVBF7.mjs → chunk-MOBXUTO5.mjs} +5 -5
- package/dist/chunk-MOBXUTO5.mjs.map +1 -0
- package/dist/chunk-O5SQJUKB.mjs +37 -0
- package/dist/chunk-O5SQJUKB.mjs.map +1 -0
- package/dist/chunk-XW34KZRY.mjs +17 -0
- package/dist/chunk-XW34KZRY.mjs.map +1 -0
- package/dist/chunk-ZUBHGSCW.mjs +18 -0
- package/dist/chunk-ZUBHGSCW.mjs.map +1 -0
- package/dist/iter-fest.d.mts +9 -15
- package/dist/iter-fest.d.ts +9 -15
- package/dist/iter-fest.iterableEvery.d.mts +24 -0
- package/dist/iter-fest.iterableEvery.d.ts +24 -0
- package/dist/{iter-fest.asyncIteratorToAsyncIterable.js → iter-fest.iterableEvery.js} +19 -15
- package/dist/iter-fest.iterableEvery.js.map +1 -0
- package/dist/iter-fest.iterableEvery.mjs +7 -0
- package/dist/iter-fest.iterableFilter.d.mts +16 -0
- package/dist/iter-fest.iterableFilter.d.ts +16 -0
- package/dist/iter-fest.iterableFilter.js +42 -0
- package/dist/iter-fest.iterableFilter.js.map +1 -0
- package/dist/iter-fest.iterableFilter.mjs +7 -0
- package/dist/iter-fest.iterableFind.d.mts +15 -0
- package/dist/iter-fest.iterableFind.d.ts +15 -0
- package/dist/iter-fest.iterableFind.js +43 -0
- package/dist/iter-fest.iterableFind.js.map +1 -0
- package/dist/iter-fest.iterableFind.mjs +7 -0
- package/dist/iter-fest.iterableForEach.d.mts +10 -0
- package/dist/iter-fest.iterableForEach.d.ts +10 -0
- package/dist/iter-fest.iterableForEach.js +40 -0
- package/dist/iter-fest.iterableForEach.js.map +1 -0
- package/dist/iter-fest.iterableForEach.mjs +7 -0
- package/dist/iter-fest.iterableGetReadable.d.mts +3 -0
- package/dist/iter-fest.iterableGetReadable.d.ts +3 -0
- package/dist/{iter-fest.readableStreamFrom.js → iter-fest.iterableGetReadable.js} +9 -9
- package/dist/iter-fest.iterableGetReadable.js.map +1 -0
- package/dist/iter-fest.iterableGetReadable.mjs +7 -0
- package/dist/iter-fest.iterableMap.d.mts +8 -0
- package/dist/iter-fest.iterableMap.d.ts +8 -0
- package/dist/iter-fest.iterableMap.js +39 -0
- package/dist/iter-fest.iterableMap.js.map +1 -0
- package/dist/iter-fest.iterableMap.mjs +7 -0
- package/dist/{iter-fest.iteratorReduce.d.mts → iter-fest.iterableReduce.d.mts} +9 -13
- package/dist/{iter-fest.iteratorReduce.d.ts → iter-fest.iterableReduce.d.ts} +9 -13
- package/dist/iter-fest.iterableReduce.js +41 -0
- package/dist/iter-fest.iterableReduce.js.map +1 -0
- package/dist/iter-fest.iterableReduce.mjs +7 -0
- package/dist/iter-fest.iterableSome.d.mts +12 -0
- package/dist/iter-fest.iterableSome.d.ts +12 -0
- package/dist/iter-fest.iterableSome.js +43 -0
- package/dist/iter-fest.iterableSome.js.map +1 -0
- package/dist/iter-fest.iterableSome.mjs +7 -0
- package/dist/iter-fest.js +168 -177
- package/dist/iter-fest.js.map +1 -1
- package/dist/iter-fest.mjs +48 -72
- package/dist/iter-fest.pushAsyncIterableIterator.d.mts +9 -0
- package/dist/iter-fest.pushAsyncIterableIterator.d.ts +9 -0
- package/dist/{iter-fest.iterableWritableStream.js → iter-fest.pushAsyncIterableIterator.js} +30 -39
- package/dist/iter-fest.pushAsyncIterableIterator.js.map +1 -0
- package/dist/iter-fest.pushAsyncIterableIterator.mjs +7 -0
- package/package.json +87 -147
- package/dist/chunk-3S6LCGE6.mjs +0 -10
- package/dist/chunk-3S6LCGE6.mjs.map +0 -1
- package/dist/chunk-BWMXKULC.mjs +0 -46
- package/dist/chunk-BWMXKULC.mjs.map +0 -1
- package/dist/chunk-FBST4AUL.mjs +0 -10
- package/dist/chunk-FBST4AUL.mjs.map +0 -1
- package/dist/chunk-FMIHIL6A.mjs +0 -10
- package/dist/chunk-FMIHIL6A.mjs.map +0 -1
- package/dist/chunk-KYMTQJIJ.mjs +0 -10
- package/dist/chunk-KYMTQJIJ.mjs.map +0 -1
- package/dist/chunk-LIMQXDFK.mjs +0 -10
- package/dist/chunk-LIMQXDFK.mjs.map +0 -1
- package/dist/chunk-OWUGLCQB.mjs +0 -10
- package/dist/chunk-OWUGLCQB.mjs.map +0 -1
- package/dist/chunk-P4OSZLEH.mjs +0 -15
- package/dist/chunk-P4OSZLEH.mjs.map +0 -1
- package/dist/chunk-QX6EMOSQ.mjs +0 -10
- package/dist/chunk-QX6EMOSQ.mjs.map +0 -1
- package/dist/chunk-R6SXIXMH.mjs +0 -10
- package/dist/chunk-R6SXIXMH.mjs.map +0 -1
- package/dist/chunk-TDHR35S7.mjs +0 -10
- package/dist/chunk-TDHR35S7.mjs.map +0 -1
- package/dist/chunk-VCKLUCOT.mjs +0 -10
- package/dist/chunk-VCKLUCOT.mjs.map +0 -1
- package/dist/chunk-XQDGXAAF.mjs +0 -10
- package/dist/chunk-XQDGXAAF.mjs.map +0 -1
- package/dist/chunk-YJSIVBF7.mjs.map +0 -1
- package/dist/chunk-YLERARWI.mjs +0 -10
- package/dist/chunk-YLERARWI.mjs.map +0 -1
- package/dist/iter-fest.asyncIteratorToAsyncIterable.d.mts +0 -3
- package/dist/iter-fest.asyncIteratorToAsyncIterable.d.ts +0 -3
- package/dist/iter-fest.asyncIteratorToAsyncIterable.js.map +0 -1
- package/dist/iter-fest.asyncIteratorToAsyncIterable.mjs +0 -7
- package/dist/iter-fest.iterableWritableStream.d.mts +0 -7
- package/dist/iter-fest.iterableWritableStream.d.ts +0 -7
- package/dist/iter-fest.iterableWritableStream.js.map +0 -1
- package/dist/iter-fest.iterableWritableStream.mjs +0 -7
- package/dist/iter-fest.iteratorDrop.d.mts +0 -12
- package/dist/iter-fest.iteratorDrop.d.ts +0 -12
- package/dist/iter-fest.iteratorDrop.js +0 -44
- package/dist/iter-fest.iteratorDrop.js.map +0 -1
- package/dist/iter-fest.iteratorDrop.mjs +0 -7
- package/dist/iter-fest.iteratorEvery.d.mts +0 -25
- package/dist/iter-fest.iteratorEvery.d.ts +0 -25
- package/dist/iter-fest.iteratorEvery.js +0 -44
- package/dist/iter-fest.iteratorEvery.js.map +0 -1
- package/dist/iter-fest.iteratorEvery.mjs +0 -7
- package/dist/iter-fest.iteratorFilter.d.mts +0 -18
- package/dist/iter-fest.iteratorFilter.d.ts +0 -18
- package/dist/iter-fest.iteratorFilter.js +0 -44
- package/dist/iter-fest.iteratorFilter.js.map +0 -1
- package/dist/iter-fest.iteratorFilter.mjs +0 -7
- package/dist/iter-fest.iteratorFind.d.mts +0 -14
- package/dist/iter-fest.iteratorFind.d.ts +0 -14
- package/dist/iter-fest.iteratorFind.js +0 -44
- package/dist/iter-fest.iteratorFind.js.map +0 -1
- package/dist/iter-fest.iteratorFind.mjs +0 -7
- package/dist/iter-fest.iteratorFlatMap.d.mts +0 -12
- package/dist/iter-fest.iteratorFlatMap.d.ts +0 -12
- package/dist/iter-fest.iteratorFlatMap.js +0 -44
- package/dist/iter-fest.iteratorFlatMap.js.map +0 -1
- package/dist/iter-fest.iteratorFlatMap.mjs +0 -7
- package/dist/iter-fest.iteratorForEach.d.mts +0 -10
- package/dist/iter-fest.iteratorForEach.d.ts +0 -10
- package/dist/iter-fest.iteratorForEach.js +0 -44
- package/dist/iter-fest.iteratorForEach.js.map +0 -1
- package/dist/iter-fest.iteratorForEach.mjs +0 -7
- package/dist/iter-fest.iteratorFrom.d.mts +0 -12
- package/dist/iter-fest.iteratorFrom.d.ts +0 -12
- package/dist/iter-fest.iteratorFrom.js +0 -44
- package/dist/iter-fest.iteratorFrom.js.map +0 -1
- package/dist/iter-fest.iteratorFrom.mjs +0 -7
- package/dist/iter-fest.iteratorMap.d.mts +0 -10
- package/dist/iter-fest.iteratorMap.d.ts +0 -10
- package/dist/iter-fest.iteratorMap.js +0 -44
- package/dist/iter-fest.iteratorMap.js.map +0 -1
- package/dist/iter-fest.iteratorMap.mjs +0 -7
- package/dist/iter-fest.iteratorMap.mjs.map +0 -1
- package/dist/iter-fest.iteratorReduce.js +0 -44
- package/dist/iter-fest.iteratorReduce.js.map +0 -1
- package/dist/iter-fest.iteratorReduce.mjs +0 -7
- package/dist/iter-fest.iteratorReduce.mjs.map +0 -1
- package/dist/iter-fest.iteratorSome.d.mts +0 -10
- package/dist/iter-fest.iteratorSome.d.ts +0 -10
- package/dist/iter-fest.iteratorSome.js +0 -44
- package/dist/iter-fest.iteratorSome.js.map +0 -1
- package/dist/iter-fest.iteratorSome.mjs +0 -7
- package/dist/iter-fest.iteratorSome.mjs.map +0 -1
- package/dist/iter-fest.iteratorTake.d.mts +0 -12
- package/dist/iter-fest.iteratorTake.d.ts +0 -12
- package/dist/iter-fest.iteratorTake.js +0 -44
- package/dist/iter-fest.iteratorTake.js.map +0 -1
- package/dist/iter-fest.iteratorTake.mjs +0 -7
- package/dist/iter-fest.iteratorTake.mjs.map +0 -1
- package/dist/iter-fest.iteratorToArray.d.mts +0 -13
- package/dist/iter-fest.iteratorToArray.d.ts +0 -13
- package/dist/iter-fest.iteratorToArray.js +0 -44
- package/dist/iter-fest.iteratorToArray.js.map +0 -1
- package/dist/iter-fest.iteratorToArray.mjs +0 -7
- package/dist/iter-fest.iteratorToArray.mjs.map +0 -1
- package/dist/iter-fest.readableStreamFrom.d.mts +0 -3
- package/dist/iter-fest.readableStreamFrom.d.ts +0 -3
- package/dist/iter-fest.readableStreamFrom.js.map +0 -1
- package/dist/iter-fest.readableStreamFrom.mjs +0 -7
- package/dist/iter-fest.readableStreamFrom.mjs.map +0 -1
- /package/dist/{iter-fest.asyncIteratorToAsyncIterable.mjs.map → iter-fest.iterableEvery.mjs.map} +0 -0
- /package/dist/{iter-fest.iterableWritableStream.mjs.map → iter-fest.iterableFilter.mjs.map} +0 -0
- /package/dist/{iter-fest.iteratorDrop.mjs.map → iter-fest.iterableFind.mjs.map} +0 -0
- /package/dist/{iter-fest.iteratorEvery.mjs.map → iter-fest.iterableForEach.mjs.map} +0 -0
- /package/dist/{iter-fest.iteratorFilter.mjs.map → iter-fest.iterableGetReadable.mjs.map} +0 -0
- /package/dist/{iter-fest.iteratorFind.mjs.map → iter-fest.iterableMap.mjs.map} +0 -0
- /package/dist/{iter-fest.iteratorFlatMap.mjs.map → iter-fest.iterableReduce.mjs.map} +0 -0
- /package/dist/{iter-fest.iteratorForEach.mjs.map → iter-fest.iterableSome.mjs.map} +0 -0
- /package/dist/{iter-fest.iteratorFrom.mjs.map → iter-fest.pushAsyncIterableIterator.mjs.map} +0 -0
package/README.md
CHANGED
|
@@ -16,22 +16,38 @@ 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
|
-
| `
|
|
25
|
-
| `
|
|
26
|
-
| `
|
|
27
|
-
| `AsyncIterable`
|
|
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
|
+
| `Observable` | `ReadableStream` | [`observableSubscribeAsReadable<T>(observable: Observable<T>): ReadableStream<T>`](#converting-an-observable-to-readablestream) |
|
|
42
|
+
| `ReadableStreamDefaultReader` | `AsyncIterableIterator` | [`readerValues`<T>(reader: ReadableStreamDefaultReader<T>): AsyncIterableIterator<T>`](#iterating-readablestreamdefaultreader) |
|
|
43
|
+
| `AsyncIterable` | `Observable` | [`observableFromAsync<T>(iterable: AsyncIterable<T>): Observable<T>`](#converting-an-asynciterable-to-observable) |
|
|
44
|
+
| `AsyncIterable`/`Iterable` | `ReadableStream` | [`iterableGetReadable<T>(iterable: AsyncIterable<T> \| Iterable<T>): ReadableStream<T>`](#converting-an-asynciterableiterable-to-readablestream) |
|
|
29
45
|
|
|
30
46
|
To convert `Observable` to `AsyncIterableIterator`, [use `ReadableStream` as intermediate format](#converting-an-observable-to-asynciterableiterator).
|
|
31
47
|
|
|
32
48
|
### Converting an iterator to iterable
|
|
33
49
|
|
|
34
|
-
`iteratorToIterable`
|
|
50
|
+
`iteratorToIterable` enable a [pure iterator](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Iterator) to be iterable using a for-loop statement.
|
|
35
51
|
|
|
36
52
|
```ts
|
|
37
53
|
const iterate = (): Iterator<number> => {
|
|
@@ -43,7 +59,7 @@ const iterate = (): Iterator<number> => {
|
|
|
43
59
|
return { value };
|
|
44
60
|
}
|
|
45
61
|
|
|
46
|
-
return { done: true, value: undefined }
|
|
62
|
+
return { done: true, value: undefined };
|
|
47
63
|
}
|
|
48
64
|
};
|
|
49
65
|
};
|
|
@@ -53,31 +69,28 @@ for (const value of iteratorToIterable(iterate())) {
|
|
|
53
69
|
}
|
|
54
70
|
```
|
|
55
71
|
|
|
56
|
-
Note: calling `[Symbol.iterator]
|
|
72
|
+
Note: calling `[Symbol.iterator]` will not refresh the iteration.
|
|
57
73
|
|
|
58
74
|
### Converting an `Observable` to `AsyncIterableIterator`
|
|
59
75
|
|
|
60
|
-
`ReadableStream` can be used
|
|
76
|
+
`ReadableStream` can be used to when converting an `Observable` to `AsyncIterableIterator`.
|
|
61
77
|
|
|
62
78
|
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
79
|
|
|
64
80
|
```ts
|
|
65
81
|
const observable = Observable.from([1, 2, 3]);
|
|
66
82
|
const readable = observableSubscribeAsReadable(observable);
|
|
67
|
-
const iterable = readerValues(readable.getReader());
|
|
68
83
|
|
|
69
|
-
for await (const value of
|
|
84
|
+
for await (const value of readerValues(readable.getReader())) {
|
|
70
85
|
console.log(value); // Prints "1", "2", "3".
|
|
71
86
|
}
|
|
72
87
|
```
|
|
73
88
|
|
|
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
89
|
### Converting an `AsyncIterable` to `Observable`
|
|
77
90
|
|
|
78
91
|
`Observable.from` converts `Iterable` into `Observable`. However, it does not convert `AsyncIterable`.
|
|
79
92
|
|
|
80
|
-
`observableFromAsync` will convert `AsyncIterable` into `Observable`.
|
|
93
|
+
`observableFromAsync` will convert `AsyncIterable` into `Observable`.
|
|
81
94
|
|
|
82
95
|
```ts
|
|
83
96
|
async function* generate() {
|
|
@@ -92,11 +105,7 @@ const next = value => console.log(value);
|
|
|
92
105
|
observable.subscribe({ next }); // Prints "1", "2", "3".
|
|
93
106
|
```
|
|
94
107
|
|
|
95
|
-
|
|
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`
|
|
108
|
+
## Converting an `Observable` to `ReadableStream`
|
|
100
109
|
|
|
101
110
|
`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
111
|
|
|
@@ -105,11 +114,12 @@ Note: `Observable` is push-based and it does not support flow control. When conv
|
|
|
105
114
|
```ts
|
|
106
115
|
const observable = Observable.from([1, 2, 3]);
|
|
107
116
|
const readable = observableSubscribeAsReadable(observable);
|
|
117
|
+
const reader = readable.getReader();
|
|
108
118
|
|
|
109
119
|
readable.pipeTo(stream.writable); // Will write 1, 2, 3.
|
|
110
120
|
```
|
|
111
121
|
|
|
112
|
-
###
|
|
122
|
+
### Iterating `ReadableStreamDefaultReader`
|
|
113
123
|
|
|
114
124
|
`readerValues` will convert default reader of `ReadableStream` into an `AsyncIterableIterator` to use in for-loop.
|
|
115
125
|
|
|
@@ -125,28 +135,20 @@ const readableStream = new ReadableStream({
|
|
|
125
135
|
}
|
|
126
136
|
});
|
|
127
137
|
|
|
128
|
-
const
|
|
129
|
-
|
|
130
|
-
for await (const value of iterable) {
|
|
138
|
+
for await (const value of readerValues(readableStream.getReader())) {
|
|
131
139
|
console.log(value); // Prints "1", "2", "3".
|
|
132
140
|
}
|
|
133
141
|
```
|
|
134
142
|
|
|
135
|
-
|
|
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).
|
|
143
|
+
## Converting an `AsyncIterable`/`Iterable` to `ReadableStream`
|
|
140
144
|
|
|
141
145
|
```ts
|
|
142
146
|
const iterable = [1, 2, 3].values();
|
|
143
|
-
const readable =
|
|
147
|
+
const readable = iterableGetReadable(iterable);
|
|
144
148
|
|
|
145
149
|
readable.pipeTo(stream.writable); // Will write 1, 2, 3.
|
|
146
150
|
```
|
|
147
151
|
|
|
148
|
-
Note: `readableStreamFrom()` will call `[Symbol.iterator]()` initially to restart the iteration where possible.
|
|
149
|
-
|
|
150
152
|
## Others
|
|
151
153
|
|
|
152
154
|
### Typed `Observable`
|
|
@@ -155,18 +157,14 @@ Note: `readableStreamFrom()` will call `[Symbol.iterator]()` initially to restar
|
|
|
155
157
|
|
|
156
158
|
### Producer-consumer queue
|
|
157
159
|
|
|
158
|
-
`
|
|
160
|
+
`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
161
|
|
|
160
|
-
|
|
162
|
+
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
163
|
|
|
162
|
-
|
|
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.
|
|
164
|
+
For a full-featured producer-consumer queue that supports flow control, use `ReadableStream` instead.
|
|
166
165
|
|
|
167
166
|
```ts
|
|
168
|
-
const iterable = new
|
|
169
|
-
const writer = iterable.getWriter();
|
|
167
|
+
const iterable = new PushAsyncIterableIterator();
|
|
170
168
|
|
|
171
169
|
(async function consumer() {
|
|
172
170
|
for await (const value of iterable) {
|
|
@@ -177,10 +175,10 @@ const writer = iterable.getWriter();
|
|
|
177
175
|
})();
|
|
178
176
|
|
|
179
177
|
(async function producer() {
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
178
|
+
iterable.push(1);
|
|
179
|
+
iterable.push(2);
|
|
180
|
+
iterable.push(3);
|
|
181
|
+
iterable.close();
|
|
184
182
|
})();
|
|
185
183
|
|
|
186
184
|
// Prints "1", "2", "3", "Done".
|
|
@@ -197,11 +195,11 @@ The `generatorWithLastValue()` and `asyncGeneratorWithLastValue()` helps bridge
|
|
|
197
195
|
```ts
|
|
198
196
|
const generator = generatorWithLastValue(
|
|
199
197
|
(function* () {
|
|
200
|
-
yield 1;
|
|
201
|
-
yield 2;
|
|
202
|
-
yield 3;
|
|
198
|
+
yield 1;
|
|
199
|
+
yield 2;
|
|
200
|
+
yield 3;
|
|
203
201
|
|
|
204
|
-
return 'end';
|
|
202
|
+
return 'end';
|
|
205
203
|
})()
|
|
206
204
|
);
|
|
207
205
|
|
|
@@ -224,42 +222,6 @@ const generator = generatorWithLastValue(
|
|
|
224
222
|
);
|
|
225
223
|
```
|
|
226
224
|
|
|
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
225
|
## Behaviors
|
|
264
226
|
|
|
265
227
|
### How this compares to the TC39 proposals?
|
|
@@ -308,21 +270,18 @@ Generator has more functionalities than iterator and array. It is not recommende
|
|
|
308
270
|
- Generator can define the return value
|
|
309
271
|
- `return { done: true, value: 'the very last value' }`
|
|
310
272
|
- 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
273
|
- Generator can receive feedback values from its iterator
|
|
313
274
|
- `generator.next('something')`, the feedback can be assigned to variable via `const feedback = yield;`
|
|
314
275
|
- For-loop cannot send feedbacks to generator
|
|
315
276
|
|
|
316
277
|
### When should I use `Iterable`, `IterableIterator` and `Iterator`?
|
|
317
278
|
|
|
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`.
|
|
279
|
+
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
280
|
|
|
320
281
|
```ts
|
|
321
|
-
function
|
|
282
|
+
function transform<T>(iterable: Iterable<T>): IterableIterator<T>;
|
|
322
283
|
```
|
|
323
284
|
|
|
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
285
|
### What is on the roadmap?
|
|
327
286
|
|
|
328
287
|
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/
|
|
1
|
+
// src/iterableGetReadable.ts
|
|
2
2
|
function isIterable(iterable) {
|
|
3
3
|
return !!(iterable && typeof iterable === "object" && Symbol.iterator in iterable);
|
|
4
4
|
}
|
|
5
|
-
function
|
|
6
|
-
const iterator = isIterable(
|
|
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
|
-
|
|
20
|
+
iterableGetReadable
|
|
21
21
|
};
|
|
22
|
-
//# sourceMappingURL=chunk-
|
|
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":[]}
|
package/dist/iter-fest.d.mts
CHANGED
|
@@ -1,37 +1,31 @@
|
|
|
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
|
-
export { asyncIteratorToAsyncIterable } from './iter-fest.asyncIteratorToAsyncIterable.mjs';
|
|
5
5
|
export { GeneratorWithLastValue, generatorWithLastValue } from './iter-fest.generatorWithLastValue.mjs';
|
|
6
6
|
export { iterableAt } from './iter-fest.iterableAt.mjs';
|
|
7
7
|
export { iterableConcat } from './iter-fest.iterableConcat.mjs';
|
|
8
8
|
export { iterableEntries } from './iter-fest.iterableEntries.mjs';
|
|
9
|
+
export { iterableEvery } from './iter-fest.iterableEvery.mjs';
|
|
10
|
+
export { iterableFilter } from './iter-fest.iterableFilter.mjs';
|
|
11
|
+
export { iterableFind } from './iter-fest.iterableFind.mjs';
|
|
9
12
|
export { iterableFindIndex } from './iter-fest.iterableFindIndex.mjs';
|
|
10
13
|
export { iterableFindLast } from './iter-fest.iterableFindLast.mjs';
|
|
11
14
|
export { iterableFindLastIndex } from './iter-fest.iterableFindLastIndex.mjs';
|
|
15
|
+
export { iterableForEach } from './iter-fest.iterableForEach.mjs';
|
|
16
|
+
export { iterableGetReadable } from './iter-fest.iterableGetReadable.mjs';
|
|
12
17
|
export { iterableIncludes } from './iter-fest.iterableIncludes.mjs';
|
|
13
18
|
export { iterableIndexOf } from './iter-fest.iterableIndexOf.mjs';
|
|
14
19
|
export { iterableJoin } from './iter-fest.iterableJoin.mjs';
|
|
15
20
|
export { iterableKeys } from './iter-fest.iterableKeys.mjs';
|
|
21
|
+
export { iterableMap } from './iter-fest.iterableMap.mjs';
|
|
22
|
+
export { iterableReduce } from './iter-fest.iterableReduce.mjs';
|
|
16
23
|
export { iterableSlice } from './iter-fest.iterableSlice.mjs';
|
|
24
|
+
export { iterableSome } from './iter-fest.iterableSome.mjs';
|
|
17
25
|
export { iterableToSpliced } from './iter-fest.iterableToSpliced.mjs';
|
|
18
26
|
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
27
|
export { iteratorToIterable } from './iter-fest.iteratorToIterable.mjs';
|
|
33
28
|
export { observableFromAsync } from './iter-fest.observableFromAsync.mjs';
|
|
34
29
|
export { observableSubscribeAsReadable } from './iter-fest.observableSubscribeAsReadable.mjs';
|
|
35
|
-
export { readableStreamFrom } from './iter-fest.readableStreamFrom.mjs';
|
|
36
30
|
export { readerValues } from './iter-fest.readerValues.mjs';
|
|
37
31
|
import 'core-js-pure/full/observable';
|
package/dist/iter-fest.d.ts
CHANGED
|
@@ -1,37 +1,31 @@
|
|
|
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
|
-
export { asyncIteratorToAsyncIterable } from './iter-fest.asyncIteratorToAsyncIterable.js';
|
|
5
5
|
export { GeneratorWithLastValue, generatorWithLastValue } from './iter-fest.generatorWithLastValue.js';
|
|
6
6
|
export { iterableAt } from './iter-fest.iterableAt.js';
|
|
7
7
|
export { iterableConcat } from './iter-fest.iterableConcat.js';
|
|
8
8
|
export { iterableEntries } from './iter-fest.iterableEntries.js';
|
|
9
|
+
export { iterableEvery } from './iter-fest.iterableEvery.js';
|
|
10
|
+
export { iterableFilter } from './iter-fest.iterableFilter.js';
|
|
11
|
+
export { iterableFind } from './iter-fest.iterableFind.js';
|
|
9
12
|
export { iterableFindIndex } from './iter-fest.iterableFindIndex.js';
|
|
10
13
|
export { iterableFindLast } from './iter-fest.iterableFindLast.js';
|
|
11
14
|
export { iterableFindLastIndex } from './iter-fest.iterableFindLastIndex.js';
|
|
15
|
+
export { iterableForEach } from './iter-fest.iterableForEach.js';
|
|
16
|
+
export { iterableGetReadable } from './iter-fest.iterableGetReadable.js';
|
|
12
17
|
export { iterableIncludes } from './iter-fest.iterableIncludes.js';
|
|
13
18
|
export { iterableIndexOf } from './iter-fest.iterableIndexOf.js';
|
|
14
19
|
export { iterableJoin } from './iter-fest.iterableJoin.js';
|
|
15
20
|
export { iterableKeys } from './iter-fest.iterableKeys.js';
|
|
21
|
+
export { iterableMap } from './iter-fest.iterableMap.js';
|
|
22
|
+
export { iterableReduce } from './iter-fest.iterableReduce.js';
|
|
16
23
|
export { iterableSlice } from './iter-fest.iterableSlice.js';
|
|
24
|
+
export { iterableSome } from './iter-fest.iterableSome.js';
|
|
17
25
|
export { iterableToSpliced } from './iter-fest.iterableToSpliced.js';
|
|
18
26
|
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
27
|
export { iteratorToIterable } from './iter-fest.iteratorToIterable.js';
|
|
33
28
|
export { observableFromAsync } from './iter-fest.observableFromAsync.js';
|
|
34
29
|
export { observableSubscribeAsReadable } from './iter-fest.observableSubscribeAsReadable.js';
|
|
35
|
-
export { readableStreamFrom } from './iter-fest.readableStreamFrom.js';
|
|
36
30
|
export { readerValues } from './iter-fest.readerValues.js';
|
|
37
31
|
import 'core-js-pure/full/observable';
|