@soffinal/stream 0.2.1 → 0.2.3
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 +118 -93
- package/dist/index.js +2 -2
- package/dist/index.js.map +8 -8
- package/dist/reactive/state.d.ts +3 -3
- package/dist/reactive/state.d.ts.map +1 -1
- package/dist/stream.d.ts +6 -14
- package/dist/stream.d.ts.map +1 -1
- package/dist/transformers/filter.d.ts +74 -13
- package/dist/transformers/filter.d.ts.map +1 -1
- package/dist/transformers/flat.d.ts.map +1 -1
- package/dist/transformers/map.d.ts +83 -13
- package/dist/transformers/map.d.ts.map +1 -1
- package/dist/transformers/merge.d.ts +1 -3
- package/dist/transformers/merge.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/transformers/filter.md +244 -120
- package/src/transformers/map.md +336 -122
- package/CHANGELOG.md +0 -22
package/README.md
CHANGED
|
@@ -5,9 +5,9 @@
|
|
|
5
5
|
[](https://opensource.org/licenses/MIT)
|
|
6
6
|
[](https://bundlephobia.com/package/@soffinal/stream)
|
|
7
7
|
|
|
8
|
-
> **
|
|
8
|
+
> **Multicast Event Pipelines with functional composition**
|
|
9
9
|
|
|
10
|
-
|
|
10
|
+
Stream provides multicast event pipelines with functional composition capabilities. It supports both push-based events (`stream.push()`) and pull-based data sources (async generators for WebSockets, file readers, EventSource, etc.). Features include async operations, stateful transformations, and built-in concurrency control with complete TypeScript integration.
|
|
11
11
|
|
|
12
12
|
## Table of Contents
|
|
13
13
|
|
|
@@ -25,34 +25,69 @@ A groundbreaking streaming library that introduces **Adaptive Reactive Programmi
|
|
|
25
25
|
|
|
26
26
|
## Features
|
|
27
27
|
|
|
28
|
-
-
|
|
29
|
-
-
|
|
30
|
-
-
|
|
31
|
-
-
|
|
32
|
-
-
|
|
33
|
-
-
|
|
34
|
-
-
|
|
35
|
-
-
|
|
36
|
-
-
|
|
37
|
-
-
|
|
38
|
-
-
|
|
39
|
-
-
|
|
40
|
-
-
|
|
41
|
-
-
|
|
28
|
+
- **Adaptive Constraints** - Transformers that learn and evolve based on stream history
|
|
29
|
+
- **Universal Primitives** - Four primitives: `filter`, `map`, `merge`, `flat`
|
|
30
|
+
- **Documentation-as-Distribution** - Copy-paste transformers embedded in JSDoc, no separate packages needed
|
|
31
|
+
- **Async-First** - Native async/await support with configurable concurrency control
|
|
32
|
+
- **Concurrency Strategies** - Sequential, concurrent-unordered, concurrent-ordered processing
|
|
33
|
+
- **Multicast Streams** - One stream, unlimited consumers
|
|
34
|
+
- **Awaitable** - `await stream` for next value
|
|
35
|
+
- **Async Iterable** - Native `for await` loop support
|
|
36
|
+
- **Pipe Composition** - Stream-to-stream functional composition
|
|
37
|
+
- **Type Guards** - Built-in TypeScript type narrowing support
|
|
38
|
+
- **Reactive State** - Stateful values with automatic change propagation
|
|
39
|
+
- **Reactive Collections** - Lists, Maps, Sets with fine-grained events
|
|
40
|
+
- **Stream Termination** - Declarative stream lifecycle control
|
|
41
|
+
- **Zero Dependencies** - Lightweight and tree-shakeable
|
|
42
|
+
- **Universal** - Node.js, browsers, Deno, Bun, Cloudflare Workers
|
|
43
|
+
- **Full TypeScript** - Complete type safety without the burden
|
|
42
44
|
|
|
43
45
|
## Quick Start
|
|
44
46
|
|
|
47
|
+
```typescript
|
|
48
|
+
import { Stream } from "@soffinal/stream";
|
|
49
|
+
|
|
50
|
+
const events = new Stream<string>();
|
|
51
|
+
|
|
52
|
+
events.listen(console.log);
|
|
53
|
+
|
|
54
|
+
events.push("Hello"); //log: Hello
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
## Examples
|
|
58
|
+
|
|
45
59
|
```typescript
|
|
46
60
|
import { Stream, State, filter, map, merge } from "@soffinal/stream";
|
|
47
61
|
|
|
48
|
-
// Create
|
|
62
|
+
// Create streams
|
|
49
63
|
const events = new Stream<string>();
|
|
50
64
|
const numbers = new Stream<number>();
|
|
51
65
|
|
|
52
|
-
//
|
|
66
|
+
// Pull-based stream from async generator
|
|
67
|
+
const websocketStream = new Stream(async function* () {
|
|
68
|
+
const ws = new WebSocket("ws://localhost:8080");
|
|
69
|
+
while (ws.readyState === WebSocket.OPEN) {
|
|
70
|
+
yield await new Promise((resolve) => {
|
|
71
|
+
ws.onmessage = (event) => resolve(JSON.parse(event.data));
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
// Simple transformations
|
|
53
77
|
const processed = events
|
|
54
|
-
.pipe(
|
|
55
|
-
.pipe(
|
|
78
|
+
.pipe(filter((msg) => msg.length > 3)) // Simple filtering
|
|
79
|
+
.pipe(map((msg) => msg.toUpperCase())); // Transform to uppercase
|
|
80
|
+
|
|
81
|
+
// Async transformations with concurrency
|
|
82
|
+
const validated = events.pipe(
|
|
83
|
+
filter(
|
|
84
|
+
async (msg) => {
|
|
85
|
+
const isValid = await validateAsync(msg);
|
|
86
|
+
return isValid;
|
|
87
|
+
},
|
|
88
|
+
{ strategy: "concurrent-ordered" }
|
|
89
|
+
) // Parallel validation, ordered results
|
|
90
|
+
);
|
|
56
91
|
|
|
57
92
|
// Stateful transformers that learn and adapt
|
|
58
93
|
const runningAverage = numbers
|
|
@@ -82,6 +117,7 @@ const delayed = processed.pipe(delay(100)); // Delay each value
|
|
|
82
117
|
|
|
83
118
|
// Multiple consumers
|
|
84
119
|
processed.listen((msg) => console.log("Processed:", msg));
|
|
120
|
+
validated.listen((msg) => console.log("Validated:", msg));
|
|
85
121
|
runningAverage.listen(({ value, average }) => console.log(`Value: ${value}, Running Average: ${average}`));
|
|
86
122
|
|
|
87
123
|
// Reactive state
|
|
@@ -152,18 +188,18 @@ for await (const event of userEvents) {
|
|
|
152
188
|
|
|
153
189
|
### Pipe: Stream-to-Stream Composition
|
|
154
190
|
|
|
155
|
-
The `pipe` method enforces
|
|
191
|
+
The `pipe` method enforces composition - it only accepts functions that return Stream instances, maintaining the infinite pipeline:
|
|
156
192
|
|
|
157
193
|
```typescript
|
|
158
194
|
// All transformers return Streams - infinite chaining
|
|
159
|
-
stream.pipe(filter(
|
|
160
|
-
stream.pipe(map(
|
|
195
|
+
stream.pipe(filter((v) => v > 0)); // → Stream<T>
|
|
196
|
+
stream.pipe(map((v) => v.toString())); // → Stream<string>
|
|
161
197
|
stream.pipe(toState("initial")); // → State<string> (extends Stream)
|
|
162
198
|
|
|
163
199
|
// Infinite chaining - every pipe returns a Stream
|
|
164
200
|
const result = stream
|
|
165
|
-
.pipe(filter(
|
|
166
|
-
.pipe(map(
|
|
201
|
+
.pipe(filter((v) => v > 0))
|
|
202
|
+
.pipe(map((v) => v * 2))
|
|
167
203
|
.pipe(take(5))
|
|
168
204
|
.pipe(delay(100))
|
|
169
205
|
.pipe(distinct()); // Always chainable
|
|
@@ -177,8 +213,8 @@ const result = stream
|
|
|
177
213
|
const numbers = new Stream<number>();
|
|
178
214
|
|
|
179
215
|
// TypeScript knows these are all Streams
|
|
180
|
-
const doubled = numbers.pipe(map(
|
|
181
|
-
const strings = numbers.pipe(map(
|
|
216
|
+
const doubled = numbers.pipe(map((n) => n * 2)); // Stream<number>
|
|
217
|
+
const strings = numbers.pipe(map((n) => n.toString())); // Stream<string>
|
|
182
218
|
const state = numbers.pipe(toState(0)); // State<number>
|
|
183
219
|
```
|
|
184
220
|
|
|
@@ -186,13 +222,27 @@ const state = numbers.pipe(toState(0)); // State<number>
|
|
|
186
222
|
|
|
187
223
|
All stream operations are built from four universal primitives with **Adaptive Constraints**:
|
|
188
224
|
|
|
189
|
-
#### 1. Filter
|
|
225
|
+
#### 1. Filter
|
|
190
226
|
|
|
191
227
|
```typescript
|
|
192
228
|
import { filter } from "@soffinal/stream";
|
|
193
229
|
|
|
194
230
|
// Simple filtering
|
|
195
|
-
stream.pipe(filter(
|
|
231
|
+
stream.pipe(filter((value) => value > 0));
|
|
232
|
+
|
|
233
|
+
// Type guard filtering
|
|
234
|
+
stream.pipe(filter((value): value is number => typeof value === "number"));
|
|
235
|
+
|
|
236
|
+
// Async filtering with concurrency strategies
|
|
237
|
+
stream.pipe(
|
|
238
|
+
filter(
|
|
239
|
+
async (value) => {
|
|
240
|
+
const isValid = await validateAsync(value);
|
|
241
|
+
return isValid;
|
|
242
|
+
},
|
|
243
|
+
{ strategy: "concurrent-ordered" }
|
|
244
|
+
) // Parallel validation, ordered results
|
|
245
|
+
);
|
|
196
246
|
|
|
197
247
|
// Stateful filtering with termination
|
|
198
248
|
stream.pipe(
|
|
@@ -201,14 +251,6 @@ stream.pipe(
|
|
|
201
251
|
return [value > 0, { count: state.count + 1 }];
|
|
202
252
|
})
|
|
203
253
|
);
|
|
204
|
-
|
|
205
|
-
// Async filtering
|
|
206
|
-
stream.pipe(
|
|
207
|
-
filter({}, async (_, value) => {
|
|
208
|
-
const isValid = await validateAsync(value);
|
|
209
|
-
return [isValid, {}];
|
|
210
|
-
})
|
|
211
|
-
);
|
|
212
254
|
```
|
|
213
255
|
|
|
214
256
|
**[📖 Complete Filter Documentation →](src/transformers/filter.md)**
|
|
@@ -219,7 +261,21 @@ stream.pipe(
|
|
|
219
261
|
import { map } from "@soffinal/stream";
|
|
220
262
|
|
|
221
263
|
// Simple transformation
|
|
222
|
-
stream.pipe(map(
|
|
264
|
+
stream.pipe(map((value) => value * 2));
|
|
265
|
+
|
|
266
|
+
// Type transformation
|
|
267
|
+
stream.pipe(map((value: number) => value.toString()));
|
|
268
|
+
|
|
269
|
+
// Async transformation with concurrency strategies
|
|
270
|
+
stream.pipe(
|
|
271
|
+
map(
|
|
272
|
+
async (value) => {
|
|
273
|
+
const enriched = await enrichWithAPI(value);
|
|
274
|
+
return enriched;
|
|
275
|
+
},
|
|
276
|
+
{ strategy: "concurrent-unordered" }
|
|
277
|
+
) // Parallel processing, results as completed
|
|
278
|
+
);
|
|
223
279
|
|
|
224
280
|
// Stateful transformation with context
|
|
225
281
|
stream.pipe(
|
|
@@ -228,14 +284,6 @@ stream.pipe(
|
|
|
228
284
|
return [{ value, runningSum: newSum }, { sum: newSum }];
|
|
229
285
|
})
|
|
230
286
|
);
|
|
231
|
-
|
|
232
|
-
// Async transformation with order preservation
|
|
233
|
-
stream.pipe(
|
|
234
|
-
map({}, async (_, value) => {
|
|
235
|
-
const enriched = await enrichWithAPI(value);
|
|
236
|
-
return [{ original: value, enriched }, {}];
|
|
237
|
-
})
|
|
238
|
-
);
|
|
239
287
|
```
|
|
240
288
|
|
|
241
289
|
**[📖 Complete Map Documentation →](src/transformers/map.md)**
|
|
@@ -273,10 +321,12 @@ const arrayStream = new Stream<number[]>();
|
|
|
273
321
|
const individualNumbers = arrayStream.pipe(flat());
|
|
274
322
|
|
|
275
323
|
arrayStream.push([1, 2, 3]); // Emits: 1, 2, 3 as separate events
|
|
324
|
+
// Type: Stream<number>
|
|
276
325
|
|
|
277
326
|
// Configurable depth flattening
|
|
278
327
|
const deepArrays = new Stream<number[][][]>();
|
|
279
328
|
const flattened = deepArrays.pipe(flat(2)); // Flatten 2 levels deep
|
|
329
|
+
// Type: Stream<number>
|
|
280
330
|
```
|
|
281
331
|
|
|
282
332
|
**[📖 Complete Flat Documentation →](src/transformers/flat.md)**
|
|
@@ -285,11 +335,9 @@ const flattened = deepArrays.pipe(flat(2)); // Flatten 2 levels deep
|
|
|
285
335
|
|
|
286
336
|
No separate repos, no CLI tools, no package management - just copy-paste ready transformers embedded in JSDoc!
|
|
287
337
|
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
#### The Educational Transparency Revolution
|
|
338
|
+
#### The Educational Transparency
|
|
291
339
|
|
|
292
|
-
|
|
340
|
+
Our approach makes **every implementation pattern visible and learnable**:
|
|
293
341
|
|
|
294
342
|
```typescript
|
|
295
343
|
// 📦 All transformers are copy-pastable from IntelliSense!
|
|
@@ -299,7 +347,6 @@ Unlike traditional libraries where transformers are minified black boxes, our ap
|
|
|
299
347
|
const searchInput = new Stream<string>(); // ← Hover here for full library
|
|
300
348
|
const searchResults = searchInput
|
|
301
349
|
.pipe(distinct()) // Copy from Stream JSDoc - learn deduplication patterns
|
|
302
|
-
.pipe(simpleFilter((q) => q.length > 2)) // Copy from Stream JSDoc - learn filtering logic
|
|
303
350
|
.pipe(take(10)) // Copy from Stream JSDoc - learn termination patterns
|
|
304
351
|
.pipe(delay(300)) // Copy from Stream JSDoc - learn async transformation
|
|
305
352
|
.pipe(simpleMap((query) => searchAPI(query))); // Copy from Stream JSDoc - learn mapping patterns
|
|
@@ -351,16 +398,6 @@ const rateLimited = <T>(maxPerSecond: number) =>
|
|
|
351
398
|
|
|
352
399
|
#### Benefits Beyond Bundle Size
|
|
353
400
|
|
|
354
|
-
**Traditional Libraries (Code-as-Distribution):**
|
|
355
|
-
|
|
356
|
-
- ❌ **Black box implementations** - Minified, unreadable code
|
|
357
|
-
- ❌ **Separate documentation** - Often outdated, disconnected from code
|
|
358
|
-
- ❌ **Limited extensibility** - Users can only use what's provided
|
|
359
|
-
- ❌ **Learning barrier** - No insight into implementation patterns
|
|
360
|
-
- ❌ **Bundle bloat** - Every transformer adds runtime cost
|
|
361
|
-
|
|
362
|
-
**Documentation-as-Distribution:**
|
|
363
|
-
|
|
364
401
|
- ✅ **Zero friction** - Copy-paste ready transformers
|
|
365
402
|
- ✅ **Perfect discoverability** - IntelliSense shows all available transformers
|
|
366
403
|
- ✅ **Always up-to-date** - Examples match current API version
|
|
@@ -393,8 +430,6 @@ Documentation-as-Distribution creates **multiplicative value**:
|
|
|
393
430
|
|
|
394
431
|
- `take(n)`, `skip(n)`, `distinct()`, `tap(fn)` - Essential filtering patterns
|
|
395
432
|
- `withIndex()`, `delay(ms)`, `pluck(key)`, `scan(fn, initial)` - Common transformation patterns
|
|
396
|
-
- `simpleFilter(predicate)` - Convenient filtering without state
|
|
397
|
-
- `simpleMap(fn)` - Convenient mapping without state
|
|
398
433
|
- `toState(initialValue)` - Convert streams to reactive state
|
|
399
434
|
- More transformers added with each release!
|
|
400
435
|
|
|
@@ -435,20 +470,20 @@ counter.value = 5;
|
|
|
435
470
|
|
|
436
471
|
// State from transformed streams
|
|
437
472
|
const source = new Stream<number>();
|
|
438
|
-
const derivedState = new State(0, source.pipe(map(
|
|
473
|
+
const derivedState = new State(0, source.pipe(map((v) => v * 2)));
|
|
439
474
|
|
|
440
475
|
// Derived state using transformers
|
|
441
|
-
const isLoggedIn = user.pipe(map(
|
|
476
|
+
const isLoggedIn = user.pipe(map((u) => u !== null));
|
|
442
477
|
|
|
443
478
|
const userDisplayName = user.pipe(
|
|
444
|
-
filter(
|
|
445
|
-
map(
|
|
479
|
+
filter((u) => u !== null),
|
|
480
|
+
map((u) => `${u.firstName} ${u.lastName}`)
|
|
446
481
|
);
|
|
447
482
|
|
|
448
483
|
// Convert streams to state with toState transformer
|
|
449
484
|
const processedState = source
|
|
450
|
-
.pipe(filter(
|
|
451
|
-
.pipe(map(
|
|
485
|
+
.pipe(filter((v) => v > 0))
|
|
486
|
+
.pipe(map((v) => v.toString()))
|
|
452
487
|
.pipe(toState("0")); // Explicit initial value
|
|
453
488
|
|
|
454
489
|
// Automatic UI updates
|
|
@@ -514,7 +549,7 @@ activeUsers.add("user1");
|
|
|
514
549
|
|
|
515
550
|
- `push(...values: T[]): void` - Emit values to all listeners
|
|
516
551
|
- `listen(callback: (value: T) => void, signal?: AbortSignal | Stream<any>): () => void` - Add listener, returns cleanup
|
|
517
|
-
- `pipe<OUTPUT
|
|
552
|
+
- `pipe<OUTPUT extends Stream<any>>(transformer: (stream: this) => OUTPUT): OUTPUT` - Apply any transformer
|
|
518
553
|
|
|
519
554
|
#### Async Interface
|
|
520
555
|
|
|
@@ -540,18 +575,21 @@ activeUsers.add("user1");
|
|
|
540
575
|
|
|
541
576
|
### Universal Transformers
|
|
542
577
|
|
|
543
|
-
#### filter(
|
|
578
|
+
#### filter(predicate, options?)
|
|
544
579
|
|
|
545
|
-
- **Simple**: `filter(
|
|
546
|
-
- **
|
|
547
|
-
- **Async**: `filter(
|
|
580
|
+
- **Simple**: `filter((value) => boolean)`
|
|
581
|
+
- **Type Guard**: `filter((value): value is Type => boolean)` (sync only)
|
|
582
|
+
- **Async**: `filter(async (value) => boolean, { strategy? })` with concurrency options
|
|
583
|
+
- **Stateful**: `filter(state, (state, value) => [boolean, newState])` (always sequential)
|
|
548
584
|
- **Termination**: Return `undefined` to terminate stream
|
|
585
|
+
- **Strategies**: `"sequential"` | `"concurrent-unordered"` | `"concurrent-ordered"`
|
|
549
586
|
|
|
550
|
-
#### map(
|
|
587
|
+
#### map(mapper, options?)
|
|
551
588
|
|
|
552
|
-
- **Simple**: `map(
|
|
553
|
-
- **
|
|
554
|
-
- **
|
|
589
|
+
- **Simple**: `map((value) => newValue)`
|
|
590
|
+
- **Async**: `map(async (value) => newValue, { strategy? })` with concurrency options
|
|
591
|
+
- **Stateful**: `map(state, (state, value) => [newValue, newState])` (always sequential)
|
|
592
|
+
- **Strategies**: `"sequential"` | `"concurrent-unordered"` | `"concurrent-ordered"`
|
|
555
593
|
|
|
556
594
|
#### merge(...streams)
|
|
557
595
|
|
|
@@ -630,20 +668,11 @@ stream.push("hello");
|
|
|
630
668
|
|
|
631
669
|
### Transformer Guides
|
|
632
670
|
|
|
633
|
-
- **[Filter Transformer →](src/transformers/filter.md)** -
|
|
634
|
-
- **[Map Transformer →](src/transformers/map.md)** -
|
|
671
|
+
- **[Filter Transformer →](src/transformers/filter.md)** - Concurrency strategies, type guards, stateful filtering, and stream termination
|
|
672
|
+
- **[Map Transformer →](src/transformers/map.md)** - Concurrency strategies, type transformations, stateful mapping, and performance optimization
|
|
635
673
|
- **[Merge Transformer →](src/transformers/merge.md)** - Stream orchestration and type-safe combination
|
|
636
674
|
- **[Flat Transformer →](src/transformers/flat.md)** - Event multiplication and array flattening
|
|
637
675
|
|
|
638
|
-
### Philosophy
|
|
639
|
-
|
|
640
|
-
**Adaptive Reactive Programming** - A new paradigm where transformers maintain state and evolve their behavior based on stream history. This enables:
|
|
641
|
-
|
|
642
|
-
- **Learning transformers** that adapt to data patterns
|
|
643
|
-
- **Stateful operations** with memory between events
|
|
644
|
-
- **Stream termination** for lifecycle control
|
|
645
|
-
- **Zero-overhead types** with perfect inference
|
|
646
|
-
|
|
647
676
|
## Contributing
|
|
648
677
|
|
|
649
678
|
We welcome contributions! Please see our [Contributing Guide](CONTRIBUTING.md) for details.
|
|
@@ -664,7 +693,3 @@ MIT © [Soffinal](https://github.com/soffinal)
|
|
|
664
693
|
Contact: <smari.sofiane@gmail.com>
|
|
665
694
|
|
|
666
695
|
---
|
|
667
|
-
|
|
668
|
-
<div align="center">
|
|
669
|
-
<strong>Pioneering Adaptive Reactive Programming</strong>
|
|
670
|
-
</div>
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
class
|
|
1
|
+
class z{_listeners=new Set;_generatorFn;_generator;_listenerAdded;_listenerRemoved;constructor(Z){this._generatorFn=Z instanceof z?()=>Z[Symbol.asyncIterator]():Z}get hasListeners(){return this._listeners.size>0}get listenerAdded(){if(!this._listenerAdded)this._listenerAdded=new z;return this._listenerAdded}get listenerRemoved(){if(!this._listenerRemoved)this._listenerRemoved=new z;return this._listenerRemoved}async*[Symbol.asyncIterator](){let Z=[],G,J=this.listen((Q)=>{Z.push(Q),G?.()});try{while(!0)if(Z.length)yield Z.shift();else await new Promise((Q)=>G=Q)}finally{J(),Z.length=0,G=void 0;return}}push(Z,...G){G.unshift(Z);for(let J of G)for(let Q of this._listeners)Q(J)}listen(Z,G){let J=this,Q;if(G instanceof AbortSignal){if(G?.aborted)return()=>{};G?.addEventListener("abort",K),Q=()=>G?.removeEventListener("abort",K)}else Q=G?.listen(K);if(J._listeners.add(Z),J._listenerAdded?.push(),J._generatorFn&&J._listeners.size===1)J._generator=J._generatorFn(),(async()=>{for await(let X of J._generator)J.push(X)})();return K;function K(){if(J._listeners.delete(Z),J._listenerRemoved?.push(),J._listeners.size===0)J._generator?.return(),J._generator=void 0;Q?.()}}then(Z){return new Promise((G)=>{let J=this.listen((Q)=>{G(Q),J()})}).then(Z)}pipe(Z){return Z(this)}}var V=(Z,G)=>{return(J)=>{if(!G||typeof G==="object"){let{strategy:K="sequential"}=G??{},X=Z;if(K==="sequential")return new z(async function*(){for await(let Y of J){let $=await X(Y);if($)yield Y;if($===void 0)return}});if(K==="concurrent-unordered")return new z(async function*(){let Y=Symbol.for("__abort"),$=new Array,_,H=J.listen(async(W)=>{let j=await X(W);if(j!==!1)j===void 0?$.push(Y):$.push(W),_?.(),_=void 0});try{while(!0)if($.length){let W=$.shift();if(W===Y)break;yield W}else await new Promise((W)=>_=W)}finally{$.length=0,H(),_=void 0}});if(K==="concurrent-ordered")return new z(async function*(){let Y=new Array,$,_=J.listen((H)=>{let W=X(H);Y.push({resultPromise:W,value:H}),(async()=>{await W,$?.(),$=void 0})()});try{while(!0)if(Y.length){let{resultPromise:H,value:W}=Y.shift(),j=await H;if(j)yield W;if(j===void 0)break}else await new Promise((H)=>$=H)}finally{Y.length=0,_(),$=void 0}})}let Q=G;return new z(async function*(){let K=Z;for await(let X of J){let Y=await Q(K,X);if(!Y)return;let[$,_]=Y;if(K=_,$)yield X}})}};var I=(Z,G)=>{return(J)=>{if(!G||typeof G==="object"){let{strategy:K="sequential"}=G??{},X=Z;if(K==="sequential")return new z(async function*(){for await(let Y of J)yield await X(Y)});if(K==="concurrent-unordered")return new z(async function*(){let Y=new Array,$,_=J.listen(async(H)=>{Y.push(await X(H)),$?.(),$=void 0});try{while(!0)if(Y.length)yield Y.shift();else await new Promise((H)=>$=H)}finally{Y.length=0,_(),$=void 0}});if(K==="concurrent-ordered")return new z(async function*(){let Y=new Array,$,_=J.listen((H)=>{let W=X(H);Y.push(W),(async()=>{await W,$?.(),$=void 0})()});try{while(!0)if(Y.length)yield await Y.shift();else await new Promise((H)=>$=H)}finally{Y.length=0,_(),$=void 0}})}let Q=G;return new z(async function*(){let K=Z;for await(let X of J){let[Y,$]=await Q(K,X);K=$,yield Y}})}};function M(...Z){return(G)=>new z(async function*(){let J=[G,...Z],Q=[],K,X=J.map((Y)=>Y.listen(($)=>{Q.push($),K?.()}));try{while(!0)if(Q.length)yield Q.shift();else await new Promise((Y)=>K=Y)}finally{X.forEach((Y)=>Y())}})}function k(Z=0){return(G)=>{return new z(async function*(){for await(let J of G)if(Array.isArray(J)){let Q=J.flat(Z);for(let K=0;K<Q.length;K++)yield Q[K]}else yield J})}}class B{_items=[];_insertStream;_deleteStream;_clearStream;constructor(Z){if(Z)this._items=[...Z];let G=this;function J(K,X){if(X===0)return 0;return K<0?(K%X+X)%X:K%X}this.insert=new Proxy((K,X)=>{let Y=K<0?Math.max(0,G._items.length+K+1):Math.min(K,G._items.length);return G._items.splice(Y,0,X),G._insertStream?.push([Y,X]),Q},{get(K,X){if(X in K)return K[X];if(!G._insertStream)G._insertStream=new z;return G._insertStream[X]}}),this.delete=new Proxy((K)=>{if(K<0||K>=G._items.length)return;let X=G._items.splice(K,1)[0];return G._deleteStream?.push([K,X]),X},{get(K,X){if(X in K)return K[X];if(!G._deleteStream)G._deleteStream=new z;return G._deleteStream[X]}}),this.clear=new Proxy(()=>{if(G._items.length>0)G._items.length=0,G._clearStream?.push()},{get(K,X){if(X in K)return K[X];if(!G._clearStream)G._clearStream=new z;return G._clearStream[X]}});let Q=new Proxy(this,{get(K,X){if(typeof X==="string"&&/^-?\d+$/.test(X)){let Y=parseInt(X);if(K._items.length===0)return;let $=J(Y,K._items.length);return K._items[$]}return K[X]},set(K,X,Y){if(typeof X==="string"&&/^-?\d+$/.test(X)){let $=parseInt(X);if(K._items.length===0)return K._items.push(Y),K._insertStream?.push([0,Y]),!0;let _=J($,K._items.length);if(K._items[_]!==Y)K._items[_]=Y,K._insertStream?.push([_,Y]);return!0}return K[X]=Y,!0}});return Q}get(Z){return this._items[Z]}get length(){return this._items.length}values(){return this._items[Symbol.iterator]()}[Symbol.iterator](){return this._items[Symbol.iterator]()}}class D extends globalThis.Map{_setStream;_deleteStream;_clearStream;constructor(Z){super(Z);let G=this;this.set=new Proxy((J,Q)=>{if(globalThis.Map.prototype.has.call(G,J)&&globalThis.Map.prototype.get.call(G,J)===Q)return G;return globalThis.Map.prototype.set.call(G,J,Q),G._setStream?.push([J,Q]),G},{get(J,Q){if(Q in J)return J[Q];if(!G._setStream)G._setStream=new z;return G._setStream[Q]}}),this.delete=new Proxy((J)=>{if(!globalThis.Map.prototype.has.call(G,J))return!1;let Q=globalThis.Map.prototype.get.call(G,J);return globalThis.Map.prototype.delete.call(G,J),G._deleteStream?.push([J,Q]),!0},{get(J,Q){if(Q in J)return J[Q];if(!G._deleteStream)G._deleteStream=new z;return G._deleteStream[Q]}}),this.clear=new Proxy(()=>{if(G.size>0)globalThis.Map.prototype.clear.call(G),G._clearStream?.push()},{get(J,Q){if(Q in J)return J[Q];if(!G._clearStream)G._clearStream=new z;return G._clearStream[Q]}})}}class F extends globalThis.Set{_addStream;_deleteStream;_clearStream;constructor(Z){super(Z);let G=this;this.add=new Proxy((J)=>{if(globalThis.Set.prototype.has.call(G,J))return G;return globalThis.Set.prototype.add.call(G,J),G._addStream?.push(J),G},{get(J,Q){if(Q in J)return J[Q];if(!G._addStream)G._addStream=new z;return G._addStream[Q]}}),this.delete=new Proxy((J)=>{if(!globalThis.Set.prototype.has.call(G,J))return!1;return globalThis.Set.prototype.delete.call(G,J),G._deleteStream?.push(J),!0},{get(J,Q){if(Q in J)return J[Q];if(!G._deleteStream)G._deleteStream=new z;return G._deleteStream[Q]}}),this.clear=new Proxy(()=>{if(G.size>0)globalThis.Set.prototype.clear.call(G),G._clearStream?.push()},{get(J,Q){if(Q in J)return J[Q];if(!G._clearStream)G._clearStream=new z;return G._clearStream[Q]}})}}class N extends z{_value;constructor(Z,G){super(G);this._value=Z}push(...Z){for(let G of Z)this.value=G}get value(){return this._value}set value(Z){this._value=Z,super.push(Z)}}export{M as merge,I as map,k as flat,V as filter,z as Stream,N as State,F as Set,D as Map,B as List};
|
|
2
2
|
|
|
3
|
-
//# debugId=
|
|
3
|
+
//# debugId=632A5D3113A6752264756E2164756E21
|
|
4
4
|
//# sourceMappingURL=index.js.map
|