@soffinal/stream 0.2.0 → 0.2.2

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 CHANGED
@@ -5,9 +5,9 @@
5
5
  [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
6
6
  [![Bundle Size](https://img.shields.io/bundlephobia/minzip/@soffinal/stream)](https://bundlephobia.com/package/@soffinal/stream)
7
7
 
8
- > **A reactive streaming library with Adaptive Constraints**
8
+ > **Enhanced event emitters with functional composition**
9
9
 
10
- A groundbreaking streaming library that introduces **Adaptive Reactive Programming** - where transformers maintain state and evolve their behavior based on stream history. Built with four universal primitives that compose into infinite possibilities.
10
+ A modern event emitter that's multicast, awaitable, async iterable, async generable, and pipeable. Like EventEmitter but with functional transformations, perfect TypeScript inference, and copy-paste transformers embedded in JSDoc.
11
11
 
12
12
  ## Table of Contents
13
13
 
@@ -18,7 +18,6 @@ A groundbreaking streaming library that introduces **Adaptive Reactive Programmi
18
18
  - [API Reference](#api-reference)
19
19
  - [Examples](#examples)
20
20
  - [Performance](#performance)
21
- - [Browser Support](#browser-support)
22
21
  - [Migration Guide](#migration-guide)
23
22
  - [Documentation](#documentation)
24
23
  - [Contributing](#contributing)
@@ -151,6 +150,38 @@ for await (const event of userEvents) {
151
150
  }
152
151
  ```
153
152
 
153
+ ### Pipe: Stream-to-Stream Composition
154
+
155
+ The `pipe` method enforces reactive composition - it only accepts functions that return Stream instances, maintaining the infinite reactive pipeline:
156
+
157
+ ```typescript
158
+ // All transformers return Streams - infinite chaining
159
+ stream.pipe(filter({}, (_, v) => [v > 0, {}])); // → Stream<T>
160
+ stream.pipe(map({}, (_, v) => [v.toString(), {}])); // → Stream<string>
161
+ stream.pipe(toState("initial")); // → State<string> (extends Stream)
162
+
163
+ // Infinite chaining - every pipe returns a Stream
164
+ const result = stream
165
+ .pipe(filter({}, (_, v) => [v > 0, {}]))
166
+ .pipe(map({}, (_, v) => [v * 2, {}]))
167
+ .pipe(take(5))
168
+ .pipe(delay(100))
169
+ .pipe(distinct()); // Always chainable
170
+ ```
171
+
172
+ **Streams are infinite** - Like event emitters, they don't terminate naturally. The `pipe` constraint ensures you maintain the reactive paradigm throughout your entire pipeline.
173
+
174
+ **Perfect TypeScript inference** - no annotations needed:
175
+
176
+ ```typescript
177
+ const numbers = new Stream<number>();
178
+
179
+ // TypeScript knows these are all Streams
180
+ const doubled = numbers.pipe(map({}, (_, n) => [n * 2, {}])); // Stream<number>
181
+ const strings = numbers.pipe(map({}, (_, n) => [n.toString(), {}])); // Stream<string>
182
+ const state = numbers.pipe(toState(0)); // State<number>
183
+ ```
184
+
154
185
  ### Universal Primitives: The Four Algebraic Operations
155
186
 
156
187
  All stream operations are built from four universal primitives with **Adaptive Constraints**:
@@ -250,47 +281,111 @@ const flattened = deepArrays.pipe(flat(2)); // Flatten 2 levels deep
250
281
 
251
282
  **[📖 Complete Flat Documentation →](src/transformers/flat.md)**
252
283
 
253
- ### Documentation-as-Distribution: Revolutionary Copy-Paste Transformers
254
-
255
- **🚀 World's First Documentation-as-Distribution System**
284
+ ### Documentation-as-Distribution: Copy-Paste Transformers
256
285
 
257
286
  No separate repos, no CLI tools, no package management - just copy-paste ready transformers embedded in JSDoc!
258
287
 
288
+ But more importantly: **Documentation-as-Distribution is actually Education-as-Distribution.**
289
+
290
+ #### The Educational Transparency Revolution
291
+
292
+ Our approach makes **every implementation pattern visible and learnable**:
293
+
259
294
  ```typescript
260
295
  // 📦 All transformers are copy-pastable from IntelliSense!
261
- // Just hover over any primitive in your IDE to see the transformer library
296
+ // Hover over 'Stream' to see the complete transformers library
262
297
 
263
- // Example: Essential transformers available via autocomplete
264
- const searchInput = new Stream<string>();
298
+ // Example: Users don't just get functions - they get implementation education
299
+ const searchInput = new Stream<string>(); // ← Hover here for full library
265
300
  const searchResults = searchInput
266
- .pipe(distinct()) // Copy from filter() JSDoc
267
- .pipe(simpleFilter((q) => q.length > 2)) // Copy from filter() JSDoc
268
- .pipe(take(10)) // Copy from filter() JSDoc
269
- .pipe(delay(300)) // Copy from map() JSDoc
270
- .pipe(simpleMap((query) => searchAPI(query))); // Copy from map() JSDoc
301
+ .pipe(distinct()) // Copy from Stream JSDoc - learn deduplication patterns
302
+ .pipe(simpleFilter((q) => q.length > 2)) // Copy from Stream JSDoc - learn filtering logic
303
+ .pipe(take(10)) // Copy from Stream JSDoc - learn termination patterns
304
+ .pipe(delay(300)) // Copy from Stream JSDoc - learn async transformation
305
+ .pipe(simpleMap((query) => searchAPI(query))); // Copy from Stream JSDoc - learn mapping patterns
271
306
  ```
272
307
 
273
- **Benefits:**
308
+ #### What Users Actually Learn
309
+
310
+ When users hover over any function in JSDoc, they see **complete implementation patterns**:
311
+
312
+ ```typescript
313
+ // Users see EXACTLY how to build transformers
314
+ const take = <T>(n: number) =>
315
+ filter<T, { count: number }>({ count: 0 }, (state, value) => {
316
+ if (state.count >= n) return; // ← Learn termination patterns
317
+ return [true, { count: state.count + 1 }]; // ← Learn state evolution
318
+ });
319
+
320
+ const distinct = <T>() =>
321
+ filter<T, { seen: Set<T> }>({ seen: new Set() }, (state, value) => {
322
+ if (state.seen.has(value)) return [false, state]; // ← Learn deduplication logic
323
+ state.seen.add(value); // ← Learn state mutation patterns
324
+ return [true, state];
325
+ });
326
+ ```
327
+
328
+ #### From Consumers to Creators
329
+
330
+ This transparency empowers users to become **transformer architects**:
331
+
332
+ ```typescript
333
+ // After learning from JSDoc examples, users create their own:
334
+ const withTimestamp = <T>() =>
335
+ map<T, {}, { value: T; timestamp: number }>(
336
+ {}, // ← Learned: empty state when no memory needed
337
+ (_, value) => [
338
+ { value, timestamp: Date.now() }, // ← Learned: transformation pattern
339
+ {}, // ← Learned: state management
340
+ ]
341
+ );
342
+
343
+ const rateLimited = <T>(maxPerSecond: number) =>
344
+ filter<T, { timestamps: number[] }>({ timestamps: [] }, (state, value) => {
345
+ const now = Date.now();
346
+ const recent = state.timestamps.filter((t) => now - t < 1000);
347
+ if (recent.length >= maxPerSecond) return [false, { timestamps: recent }];
348
+ return [true, { timestamps: [...recent, now] }];
349
+ });
350
+ ```
351
+
352
+ #### Benefits Beyond Bundle Size
274
353
 
275
354
  - ✅ **Zero friction** - Copy-paste ready transformers
276
355
  - ✅ **Perfect discoverability** - IntelliSense shows all available transformers
277
356
  - ✅ **Always up-to-date** - Examples match current API version
278
357
  - ✅ **No ecosystem fragmentation** - Everything in one place
279
- - ✅ **Self-documenting** - Usage examples included
358
+ - ✅ **Educational transparency** - Users learn implementation patterns
359
+ - ✅ **Infinite extensibility** - Users become transformer creators
360
+ - ✅ **Self-documenting** - Usage examples included with working code
361
+ - ✅ **Zero bundle cost** - JSDoc stripped at compile time
362
+
363
+ #### The Network Effect
364
+
365
+ Documentation-as-Distribution creates **multiplicative value**:
366
+
367
+ 1. **User discovers** transformer in JSDoc
368
+ 2. **User learns** implementation pattern
369
+ 3. **User creates** custom transformers for their domain
370
+ 4. **User shares** patterns with their team
371
+ 5. **Team creates** hundreds of variations
372
+ 6. **Knowledge multiplies** exponentially across the community
280
373
 
281
374
  **How it works:**
282
375
 
283
- 1. Hover over `filter()`, `map()`, `merge()`, or `flat()` in your IDE
284
- 2. Browse the 📦 COPY-PASTE TRANSFORMER examples
376
+ 1. Hover over `Stream` in your IDE to see the complete transformers library
377
+ 2. Or hover over individual functions for quick references
285
378
  3. Copy the transformer you need
286
379
  4. Use immediately - perfect TypeScript inference included!
380
+ 5. **Learn the patterns** and create your own infinite variations
287
381
 
288
382
  **Available Transformers (via JSDoc):**
289
383
 
290
- - `take(n)`, `skip(n)`, `distinct()` - Essential filtering
291
- - `withIndex()`, `delay(ms)`, `pluck(key)` - Common transformations
384
+ - `take(n)`, `skip(n)`, `distinct()`, `tap(fn)` - Essential filtering patterns
385
+ - `withIndex()`, `delay(ms)`, `pluck(key)`, `scan(fn, initial)` - Common transformation patterns
292
386
  - `simpleFilter(predicate)` - Convenient filtering without state
293
387
  - `simpleMap(fn)` - Convenient mapping without state
388
+ - `toState(initialValue)` - Convert streams to reactive state
294
389
  - More transformers added with each release!
295
390
 
296
391
  **📊 Bundle Size Impact:**
@@ -300,6 +395,8 @@ const searchResults = searchInput
300
395
  - **Tree-shaking**: Only imported functions included in final bundle
301
396
  - **JSDoc transformers**: "Free" - rich transformer library without production cost
302
397
 
398
+ **You're not just building applications - you're learning a paradigm that scales infinitely.**
399
+
303
400
  ### Manual Composition
304
401
 
305
402
  ```typescript
@@ -326,6 +423,10 @@ console.log(counter.value); // 0
326
423
  // Write triggers all listeners
327
424
  counter.value = 5;
328
425
 
426
+ // State from transformed streams
427
+ const source = new Stream<number>();
428
+ const derivedState = new State(0, source.pipe(map({}, (_, v) => [v * 2, {}])));
429
+
329
430
  // Derived state using transformers
330
431
  const isLoggedIn = user.pipe(map({}, (_, u) => [u !== null, {}]));
331
432
 
@@ -334,6 +435,12 @@ const userDisplayName = user.pipe(
334
435
  map({}, (_, u) => [`${u.firstName} ${u.lastName}`, {}])
335
436
  );
336
437
 
438
+ // Convert streams to state with toState transformer
439
+ const processedState = source
440
+ .pipe(filter({}, (_, v) => [v > 0, {}]))
441
+ .pipe(map({}, (_, v) => [v.toString(), {}]))
442
+ .pipe(toState("0")); // Explicit initial value
443
+
337
444
  // Automatic UI updates
338
445
  isLoggedIn.listen((loggedIn) => {
339
446
  document.body.classList.toggle("authenticated", loggedIn);
@@ -397,7 +504,7 @@ activeUsers.add("user1");
397
504
 
398
505
  - `push(...values: T[]): void` - Emit values to all listeners
399
506
  - `listen(callback: (value: T) => void, signal?: AbortSignal | Stream<any>): () => void` - Add listener, returns cleanup
400
- - `pipe<U>(transformer: (stream: Stream<T>) => Stream<U>): Stream<U>` - Apply functional transformer
507
+ - `pipe<OUTPUT>(transformer: (stream: this) => OUTPUT): OUTPUT` - Apply any transformer (flexible return type)
401
508
 
402
509
  #### Async Interface
403
510
 
@@ -412,6 +519,11 @@ activeUsers.add("user1");
412
519
 
413
520
  ### State\<T> extends Stream\<T>
414
521
 
522
+ #### Constructor
523
+
524
+ - `new State(initialValue: T)` - Create state with initial value
525
+ - `new State(initialValue: T, stream: Stream<T>)` - Create state from stream
526
+
415
527
  #### Additional Properties
416
528
 
417
529
  - `value: T` - Current state value (get/set)
@@ -542,7 +654,3 @@ MIT © [Soffinal](https://github.com/soffinal)
542
654
  Contact: <smari.sofiane@gmail.com>
543
655
 
544
656
  ---
545
-
546
- <div align="center">
547
- <strong>Pioneering Adaptive Reactive Programming</strong>
548
- </div>
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
1
  export * from "./stream.ts";
2
- export * from "./transformers";
3
- export * from "./reactive";
2
+ export * from "./transformers/index.ts";
3
+ export * from "./reactive/index.ts";
4
4
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,YAAY,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,cAAc,yBAAyB,CAAC;AACxC,cAAc,qBAAqB,CAAC"}
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- class z{_listeners=new Set;_generatorFn;_generator;_listenerAdded;_listenerRemoved;constructor($){this._generatorFn=$}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 $=[],G,J=this.listen((Q)=>{$.push(Q),G?.()});try{while(!0)if($.length)yield $.shift();else await new Promise((Q)=>G=Q)}finally{J(),$.length=0,G=void 0;return}}push($,...G){G.unshift($);for(let J of G)for(let Q of this._listeners)Q(J)}listen($,G){let J=this,Q;if(G instanceof AbortSignal){if(G?.aborted)return()=>{};G?.addEventListener("abort",X),Q=()=>G?.removeEventListener("abort",X)}else Q=G?.listen(X);if(J._listeners.add($),J._listenerAdded?.push(),J._generatorFn&&J._listeners.size===1)J._generator=J._generatorFn(),(async()=>{for await(let Z of J._generator)J.push(Z)})();return X;function X(){if(J._listeners.delete($),J._listenerRemoved?.push(),J._listeners.size===0)J._generator?.return(),J._generator=void 0;Q?.()}}then($){return new Promise((G)=>{let J=this.listen((Q)=>{G(Q),J()})}).then($)}pipe($){return $(this)}}function _($,G){return(J)=>new z(async function*(){let Q=$;for await(let X of J){let Z=await G(Q,X);if(!Z)return;let[B,H]=Z;if(Q=H,B)yield X}})}function N($,G){return(J)=>new z(async function*(){let Q=$;for await(let X of J){let[Z,B]=await G(Q,X);Q=B,yield Z}})}function O(...$){return(G)=>new z(async function*(){let J=[G,...$],Q=[],X,Z=J.map((B)=>B.listen((H)=>{Q.push(H),X?.()}));try{while(!0)if(Q.length)yield Q.shift();else await new Promise((B)=>X=B)}finally{Z.forEach((B)=>B())}})}function R($=0){return(G)=>{return new z(async function*(){for await(let J of G)if(Array.isArray(J)){let Q=J.flat($);for(let X=0;X<Q.length;X++)yield Q[X]}else yield J})}}class K{_items=[];_insertStream;_deleteStream;_clearStream;constructor($){if($)this._items=[...$];let G=this;function J(X,Z){if(Z===0)return 0;return X<0?(X%Z+Z)%Z:X%Z}this.insert=new Proxy((X,Z)=>{let B=X<0?Math.max(0,G._items.length+X+1):Math.min(X,G._items.length);return G._items.splice(B,0,Z),G._insertStream?.push([B,Z]),Q},{get(X,Z){if(Z in X)return X[Z];if(!G._insertStream)G._insertStream=new z;return G._insertStream[Z]}}),this.delete=new Proxy((X)=>{if(X<0||X>=G._items.length)return;let Z=G._items.splice(X,1)[0];return G._deleteStream?.push([X,Z]),Z},{get(X,Z){if(Z in X)return X[Z];if(!G._deleteStream)G._deleteStream=new z;return G._deleteStream[Z]}}),this.clear=new Proxy(()=>{if(G._items.length>0)G._items.length=0,G._clearStream?.push()},{get(X,Z){if(Z in X)return X[Z];if(!G._clearStream)G._clearStream=new z;return G._clearStream[Z]}});let Q=new Proxy(this,{get(X,Z){if(typeof Z==="string"&&/^-?\d+$/.test(Z)){let B=parseInt(Z);if(X._items.length===0)return;let H=J(B,X._items.length);return X._items[H]}return X[Z]},set(X,Z,B){if(typeof Z==="string"&&/^-?\d+$/.test(Z)){let H=parseInt(Z);if(X._items.length===0)return X._items.push(B),X._insertStream?.push([0,B]),!0;let W=J(H,X._items.length);if(X._items[W]!==B)X._items[W]=B,X._insertStream?.push([W,B]);return!0}return X[Z]=B,!0}});return Q}get($){return this._items[$]}get length(){return this._items.length}values(){return this._items[Symbol.iterator]()}[Symbol.iterator](){return this._items[Symbol.iterator]()}}class j extends globalThis.Map{_setStream;_deleteStream;_clearStream;constructor($){super($);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 D extends globalThis.Set{_addStream;_deleteStream;_clearStream;constructor($){super($);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 q extends z{_value;constructor($){super();this._value=$}push(...$){for(let G of $)this.value=G}get value(){return this._value}set value($){this._value=$,super.push($)}}export{O as merge,N as map,R as flat,_ as filter,z as Stream,q as State,D as Set,j as Map,K as List};
1
+ class Z{_listeners=new Set;_generatorFn;_generator;_listenerAdded;_listenerRemoved;constructor(Y){this._generatorFn=Y instanceof Z?()=>Y[Symbol.asyncIterator]():Y}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 Y=[],G,J=this.listen((K)=>{Y.push(K),G?.()});try{while(!0)if(Y.length)yield Y.shift();else await new Promise((K)=>G=K)}finally{J(),Y.length=0,G=void 0;return}}push(Y,...G){G.unshift(Y);for(let J of G)for(let K of this._listeners)K(J)}listen(Y,G){let J=this,K;if(G instanceof AbortSignal){if(G?.aborted)return()=>{};G?.addEventListener("abort",Q),K=()=>G?.removeEventListener("abort",Q)}else K=G?.listen(Q);if(J._listeners.add(Y),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 Q;function Q(){if(J._listeners.delete(Y),J._listenerRemoved?.push(),J._listeners.size===0)J._generator?.return(),J._generator=void 0;K?.()}}then(Y){return new Promise((G)=>{let J=this.listen((K)=>{G(K),J()})}).then(Y)}pipe(Y){return Y(this)}}function F(Y,G){return(J)=>new Z(async function*(){let K=Y;for await(let Q of J){let X=await G(K,Q);if(!X)return;let[$,z]=X;if(K=z,$)yield Q}})}function _(Y,G){return(J)=>new Z(async function*(){let K=Y;for await(let Q of J){let[X,$]=await G(K,Q);K=$,yield X}})}function V(...Y){return(G)=>new Z(async function*(){let J=[G,...Y],K=[],Q,X=J.map(($)=>$.listen((z)=>{K.push(z),Q?.()}));try{while(!0)if(K.length)yield K.shift();else await new Promise(($)=>Q=$)}finally{X.forEach(($)=>$())}})}function E(Y=0){return(G)=>{return new Z(async function*(){for await(let J of G)if(Array.isArray(J)){let K=J.flat(Y);for(let Q=0;Q<K.length;Q++)yield K[Q]}else yield J})}}class H{_items=[];_insertStream;_deleteStream;_clearStream;constructor(Y){if(Y)this._items=[...Y];let G=this;function J(Q,X){if(X===0)return 0;return Q<0?(Q%X+X)%X:Q%X}this.insert=new Proxy((Q,X)=>{let $=Q<0?Math.max(0,G._items.length+Q+1):Math.min(Q,G._items.length);return G._items.splice($,0,X),G._insertStream?.push([$,X]),K},{get(Q,X){if(X in Q)return Q[X];if(!G._insertStream)G._insertStream=new Z;return G._insertStream[X]}}),this.delete=new Proxy((Q)=>{if(Q<0||Q>=G._items.length)return;let X=G._items.splice(Q,1)[0];return G._deleteStream?.push([Q,X]),X},{get(Q,X){if(X in Q)return Q[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(Q,X){if(X in Q)return Q[X];if(!G._clearStream)G._clearStream=new Z;return G._clearStream[X]}});let K=new Proxy(this,{get(Q,X){if(typeof X==="string"&&/^-?\d+$/.test(X)){let $=parseInt(X);if(Q._items.length===0)return;let z=J($,Q._items.length);return Q._items[z]}return Q[X]},set(Q,X,$){if(typeof X==="string"&&/^-?\d+$/.test(X)){let z=parseInt(X);if(Q._items.length===0)return Q._items.push($),Q._insertStream?.push([0,$]),!0;let B=J(z,Q._items.length);if(Q._items[B]!==$)Q._items[B]=$,Q._insertStream?.push([B,$]);return!0}return Q[X]=$,!0}});return K}get(Y){return this._items[Y]}get length(){return this._items.length}values(){return this._items[Symbol.iterator]()}[Symbol.iterator](){return this._items[Symbol.iterator]()}}class O extends globalThis.Map{_setStream;_deleteStream;_clearStream;constructor(Y){super(Y);let G=this;this.set=new Proxy((J,K)=>{if(globalThis.Map.prototype.has.call(G,J)&&globalThis.Map.prototype.get.call(G,J)===K)return G;return globalThis.Map.prototype.set.call(G,J,K),G._setStream?.push([J,K]),G},{get(J,K){if(K in J)return J[K];if(!G._setStream)G._setStream=new Z;return G._setStream[K]}}),this.delete=new Proxy((J)=>{if(!globalThis.Map.prototype.has.call(G,J))return!1;let K=globalThis.Map.prototype.get.call(G,J);return globalThis.Map.prototype.delete.call(G,J),G._deleteStream?.push([J,K]),!0},{get(J,K){if(K in J)return J[K];if(!G._deleteStream)G._deleteStream=new Z;return G._deleteStream[K]}}),this.clear=new Proxy(()=>{if(G.size>0)globalThis.Map.prototype.clear.call(G),G._clearStream?.push()},{get(J,K){if(K in J)return J[K];if(!G._clearStream)G._clearStream=new Z;return G._clearStream[K]}})}}class W extends globalThis.Set{_addStream;_deleteStream;_clearStream;constructor(Y){super(Y);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,K){if(K in J)return J[K];if(!G._addStream)G._addStream=new Z;return G._addStream[K]}}),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,K){if(K in J)return J[K];if(!G._deleteStream)G._deleteStream=new Z;return G._deleteStream[K]}}),this.clear=new Proxy(()=>{if(G.size>0)globalThis.Set.prototype.clear.call(G),G._clearStream?.push()},{get(J,K){if(K in J)return J[K];if(!G._clearStream)G._clearStream=new Z;return G._clearStream[K]}})}}class j extends Z{_value;constructor(Y,G){G?super(G):super(),this._value=Y}push(...Y){for(let G of Y)this.value=G}get value(){return this._value}set value(Y){this._value=Y,super.push(Y)}}export{V as merge,_ as map,E as flat,F as filter,Z as Stream,j as State,W as Set,O as Map,H as List};
2
2
 
3
- //# debugId=246A6A307321826B64756E2164756E21
3
+ //# debugId=C7D29CD74B2C788064756E2164756E21
4
4
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -2,17 +2,17 @@
2
2
  "version": 3,
3
3
  "sources": ["../src/stream.ts", "../src/transformers/filter.ts", "../src/transformers/map.ts", "../src/transformers/merge.ts", "../src/transformers/flat.ts", "../src/reactive/list.ts", "../src/reactive/map.ts", "../src/reactive/set.ts", "../src/reactive/state.ts"],
4
4
  "sourcesContent": [
5
- "export type ValueOf<STREAM> = STREAM extends Stream<infer VALUE> ? VALUE : never;\n\n/**\n * A reactive streaming library that provides async-first data structures with built-in event streams.\n *\n * @template VALUE - The type of values that flow through the stream\n *\n * @example\n * ```typescript\n * // Basic usage\n * const stream = new Stream<number>();\n * stream.listen(value => console.log(value));\n * stream.push(1, 2, 3);\n *\n * // With async generator\n * const timerStream = new Stream(async function* () {\n * let count = 0;\n * while (count < 5) {\n * yield count++;\n * await new Promise(resolve => setTimeout(resolve, 1000));\n * }\n * });\n *\n * // Async iteration\n * for await (const value of stream) {\n * console.log(value);\n * if (value === 10) break;\n * }\n * ```\n */\nexport class Stream<VALUE = unknown> implements AsyncIterable<VALUE> {\n protected _listeners: Set<(value: VALUE) => void> = new Set<(value: VALUE) => void>();\n protected _generatorFn: (() => AsyncGenerator<VALUE, void>) | undefined;\n protected _generator: AsyncGenerator<VALUE, void> | undefined;\n protected _listenerAdded: Stream<void> | undefined;\n protected _listenerRemoved: Stream<void> | undefined;\n\n /**\n * Creates a new Stream instance.\n *\n * @param generatorFn - Optional async generator function to produce values you can use it for creating stream with custom transformation\n *\n * @example\n * ```typescript\n * // Empty stream\n * const stream = new Stream<string>();\n *\n * // Stream with generator\n * const countdown = new Stream(async function* () {\n * for (let i = 5; i > 0; i--) {\n * yield i;\n * await new Promise(resolve => setTimeout(resolve, 1000));\n * }\n * });\n *\n * // Stream with custom transformer\n * function filter<VALUE>(source:Stream<VALUE>,predicate:(value:VALUE) => boolean):Stream<VALUE>{\n * return new Stream<VALUE>(async function* () {\n * for await (const value of source) {\n * if (predicate(value)) yield value ;\n * }\n * });\n * }\n * const source = new Stream<number>();\n * const even = filter(source,v=> v % 2 === 0)\n * even.listen(console.log);\n * source.push(1, 2, 3, 4); // 2,4\n * ```\n */\n constructor();\n constructor(generatorFn: () => AsyncGenerator<VALUE, void>);\n constructor(generatorFn?: () => AsyncGenerator<VALUE, void>) {\n this._generatorFn = generatorFn;\n }\n\n /**\n * Returns true if the stream has active listeners.\n *\n * @example\n * ```typescript\n * const stream = new Stream<number>();\n * console.log(stream.hasListeners); // false\n *\n * const cleanup = stream.listen(value => console.log(value));\n * console.log(stream.hasListeners); // true\n *\n * cleanup();\n * console.log(stream.hasListeners); // false\n * ```\n */\n get hasListeners(): boolean {\n return this._listeners.size > 0;\n }\n\n /**\n * Stream that emits when a listener is added.\n *\n * @example\n * ```typescript\n * const stream = new Stream<number>();\n * stream.listenerAdded.listen(() => console.log('Listener added'));\n *\n * stream.listen(value => console.log(value)); // Triggers 'Listener added'\n * ```\n */\n get listenerAdded(): Stream<void> {\n if (!this._listenerAdded) this._listenerAdded = new Stream<void>();\n return this._listenerAdded;\n }\n\n /**\n * Stream that emits when a listener is removed.\n *\n * @example\n * ```typescript\n * const stream = new Stream<number>();\n * stream.listenerRemoved.listen(() => console.log('Listener removed'));\n *\n * const cleanup = stream.listen(value => console.log(value));\n * cleanup(); // Triggers 'Listener removed'\n * ```\n */\n get listenerRemoved(): Stream<void> {\n if (!this._listenerRemoved) this._listenerRemoved = new Stream<void>();\n return this._listenerRemoved;\n }\n async *[Symbol.asyncIterator](): AsyncGenerator<VALUE, void> {\n const queue: VALUE[] = [];\n let resolver: Function | undefined;\n\n const abort = this.listen((value) => {\n queue.push(value);\n resolver?.();\n });\n\n try {\n while (true) {\n if (queue.length) yield queue.shift()!;\n else await new Promise<void>((resolve) => (resolver = resolve));\n }\n } finally {\n abort();\n queue.length = 0;\n resolver = undefined;\n return;\n }\n }\n\n /**\n * Pushes one or more values to all listeners.\n *\n * @param value - The first value to push\n * @param values - Additional values to push\n *\n * @example\n * ```typescript\n * const stream = new Stream<number>();\n * stream.listen(value => console.log('Received:', value));\n *\n * stream.push(1); // Received: 1\n * stream.push(2, 3, 4); // Received: 2, Received: 3, Received: 4\n * ```\n */\n push(value: VALUE, ...values: VALUE[]): void {\n values.unshift(value);\n for (const value of values) {\n for (const listener of this._listeners) {\n listener(value);\n }\n }\n }\n\n /**\n * Adds a listener to the stream.\n *\n * @param listener - Function to call when values are pushed\n * @param signal - Optional AbortSignal for cleanup\n * @returns Cleanup function to remove the listener\n *\n * @example\n * ```typescript\n * const stream = new Stream<string>();\n *\n * // Basic listener\n * const cleanup = stream.listen(value => console.log(value));\n *\n * // With AbortSignal\n * const controller = new AbortController();\n * stream.listen(value => console.log(value), controller.signal);\n * controller.abort(); // Removes listener\n *\n * // Manual cleanup\n * cleanup();\n * ```\n */\n listen(listener: (value: VALUE) => void, signal?: AbortSignal | Stream<any>): () => void {\n const self = this;\n let signalAbort: Function | undefined;\n\n if (signal instanceof AbortSignal) {\n if (signal?.aborted) return () => {};\n signal?.addEventListener(\"abort\", abort);\n signalAbort = () => signal?.removeEventListener(\"abort\", abort);\n } else {\n signalAbort = signal?.listen(abort);\n }\n\n self._listeners.add(listener);\n\n self._listenerAdded?.push();\n\n if (self._generatorFn && self._listeners.size === 1) {\n self._generator = self._generatorFn();\n (async () => {\n for await (const value of self._generator!) {\n self.push(value);\n }\n })();\n }\n return abort;\n function abort(): void {\n self._listeners.delete(listener);\n self._listenerRemoved?.push();\n if (self._listeners.size === 0) {\n self._generator?.return();\n self._generator = undefined;\n }\n signalAbort?.();\n }\n }\n\n /**\n * Promise-like interface that resolves with the next value.\n *\n * @param onfulfilled - Optional transformation function\n * @returns Promise that resolves with the first value\n *\n * @example\n * ```typescript\n * const stream = new Stream<number>();\n *\n * setTimeout(()=>{\n * stream.push(5);\n * })\n * // Wait for first value\n * const firstValue = await stream; // Resolves promises with 5\n *\n *\n * ```\n */\n then(onfulfilled?: ((value: VALUE) => VALUE | PromiseLike<VALUE>) | null): Promise<VALUE> {\n return new Promise<VALUE>((resolve) => {\n const abort = this.listen((value) => {\n resolve(value);\n abort();\n });\n }).then(onfulfilled);\n }\n\n /**\n * Applies a transformer function to this stream, enabling functional composition.\n *\n * @param transformer - Function that takes a stream and returns a transformed stream\n * @returns New stream with the transformation applied\n *\n * @example\n * ```typescript\n * const numbers = new Stream<number>();\n *\n * // Using built-in transformers\n * const result = numbers\n * .pipe(filter(n => n > 0))\n * .pipe(map(n => n * 2))\n * .pipe(group(batch => batch.length >= 3));\n *\n * // Custom transformer\n * const throttle = <T>(ms: number) => (stream: Stream<T>) =>\n * new Stream<T>(async function* () {\n * let lastEmit = 0;\n * for await (const value of stream) {\n * const now = Date.now();\n * if (now - lastEmit >= ms) {\n * yield value;\n * lastEmit = now;\n * }\n * }\n * });\n *\n * numbers.pipe(throttle(1000));\n * ```\n */\n pipe<OUTPUT>(transformer: (stream: Stream<VALUE>) => Stream<OUTPUT>): Stream<OUTPUT> {\n return transformer(this);\n }\n}\n",
6
- "import { Stream } from \"../stream.ts\";\n\n/**\n * Adaptive filter transformer that maintains state and can terminate streams.\n *\n * @template VALUE - The type of values flowing through the stream\n * @template STATE - The type of the internal state object\n *\n * @param initialState - Initial state object for the transformer\n * @param predicate - Function that determines if a value should pass through\n * - Returns `[boolean, newState]` to continue with updated state\n * - Returns `void` or `undefined` to terminate the stream\n * - Can be async for complex filtering logic\n *\n * @returns A transformer function that can be used with `.pipe()`\n *\n * @example\n * // Simple filtering\n * stream.pipe(filter({}, (_, value) => [value > 0, {}]))\n *\n * @example\n * // Async filtering\n * stream.pipe(\n * filter({}, async (_, value) => {\n * const valid = await validate(value);\n * return [valid, {}];\n * })\n * )\n *\n * @example\n * // 📦 COPY-PASTE TRANSFORMER: simpleFilter() - Simple predicate filtering\n * const simpleFilter = <T>(predicate: (value: T) => boolean | Promise<boolean>) =>\n * filter<T, {}>({}, async (_, value) => {\n * const shouldPass = await predicate(value);\n * return [shouldPass, {}];\n * });\n *\n * @example\n * // 📦 COPY-PASTE TRANSFORMER: take(n) - Limit to N items\n * const take = <T>(n: number) =>\n * filter<T, { count: number }>({ count: 0 }, (state, value) => {\n * if (state.count >= n) return;\n * return [true, { count: state.count + 1 }];\n * });\n *\n * @example\n * // 📦 COPY-PASTE TRANSFORMER: skip(n) - Skip first N items\n * const skip = <T>(n: number) =>\n * filter<T, { count: number }>({ count: 0 }, (state, value) => {\n * const newCount = state.count + 1;\n * return [newCount > n, { count: newCount }];\n * });\n *\n * @example\n * // 📦 COPY-PASTE TRANSFORMER: distinct() - Remove duplicates\n * const distinct = <T>() =>\n * filter<T, { seen: Set<T> }>({ seen: new Set() }, (state, value) => {\n * if (state.seen.has(value)) return [false, state];\n * state.seen.add(value);\n * return [true, state];\n * });\n *\n */\nexport function filter<VALUE, STATE extends Record<string, unknown> = {}>(\n initialState: STATE,\n predicate: (state: STATE, value: VALUE) => [boolean, STATE] | void | Promise<[boolean, STATE] | void>\n): (stream: Stream<VALUE>) => Stream<VALUE> {\n return (stream: Stream<VALUE>): Stream<VALUE> =>\n new Stream<VALUE>(async function* () {\n let currentState = initialState;\n\n for await (const value of stream) {\n const result = await predicate(currentState, value);\n if (!result) return;\n const [emit, state] = result;\n currentState = state;\n if (emit) {\n yield value;\n }\n }\n });\n}\n",
7
- "import { Stream } from \"../stream.ts\";\n\n/**\n * Adaptive map transformer that transforms values while maintaining state.\n *\n * @template VALUE - The type of input values\n * @template STATE - The type of the internal state object\n * @template MAPPED - The type of output values after transformation\n *\n * @param initialState - Initial state object for the transformer\n * @param predicate - Function that transforms values and updates state\n * - Must return `[transformedValue, newState]`\n * - Can be async for complex transformations\n * - Preserves order even with async operations\n *\n * @returns A transformer function that can be used with `.pipe()`\n *\n * @example\n * // Simple transformation\n * stream.pipe(map({}, (_, value) => [value * 2, {}]))\n *\n * @example\n * // Async transformation\n * stream.pipe(\n * map({}, async (_, value) => {\n * const result = await process(value);\n * return [result, {}];\n * })\n * )\n *\n * @example\n * // 📦 COPY-PASTE TRANSFORMER: simpleMap() - Simple transformation\n * const simpleMap = <T, U>(fn: (value: T) => U | Promise<U>) =>\n * map<T, {}, U>({}, async (_, value) => {\n * const result = await fn(value);\n * return [result, {}];\n * });\n *\n * @example\n * // 📦 COPY-PASTE TRANSFORMER: withIndex() - Add index to values\n * const withIndex = <T>() =>\n * map<T, { index: number }, { value: T; index: number }>(\n * { index: 0 },\n * (state, value) => [\n * { value, index: state.index },\n * { index: state.index + 1 }\n * ]\n * );\n *\n * @example\n * // 📦 COPY-PASTE TRANSFORMER: delay(ms) - Delay each value\n * const delay = <T>(ms: number) =>\n * map<T, {}, T>({}, async (_, value) => {\n * await new Promise(resolve => setTimeout(resolve, ms));\n * return [value, {}];\n * });\n *\n * @example\n * // 📦 COPY-PASTE TRANSFORMER: pluck(key) - Extract property\n * const pluck = <T, K extends keyof T>(key: K) =>\n * map<T, {}, T[K]>({}, (_, value) => [value[key], {}]);\n *\n */\nexport function map<VALUE, STATE extends Record<string, unknown>, MAPPED>(\n initialState: STATE,\n predicate: (state: STATE, value: VALUE) => [MAPPED, STATE] | Promise<[MAPPED, STATE]>\n): (stream: Stream<VALUE>) => Stream<MAPPED> {\n return (stream: Stream<VALUE>): Stream<MAPPED> =>\n new Stream<MAPPED>(async function* () {\n let currentState = initialState;\n for await (const value of stream) {\n const [mapped, state] = await predicate(currentState, value);\n currentState = state;\n yield mapped;\n }\n });\n}\n",
8
- "import { Stream } from \"../stream.ts\";\n\ntype ValueOf<STREAM> = STREAM extends Stream<infer VALUE> ? VALUE : never;\n\n/**\n * Merge multiple streams into a single stream with temporal ordering.\n * \n * @template VALUE - The type of values from the source stream\n * @template STREAMS - Tuple type of additional streams to merge\n * \n * @param streams - Additional streams to merge with the source stream\n * \n * @returns A transformer that merges all streams into one with union types\n * \n * @example\n * // Basic merge with type safety\n * const numbers = new Stream<number>();\n * const strings = new Stream<string>();\n * const merged = numbers.pipe(merge(strings));\n * // Type: Stream<number | string>\n * \n * @example\n * // Multiple streams\n * const stream1 = new Stream<number>();\n * const stream2 = new Stream<string>();\n * const stream3 = new Stream<boolean>();\n * \n * const combined = stream1.pipe(merge(stream2, stream3));\n * // Type: Stream<number | string | boolean>\n * \n\n */\nexport function merge<VALUE, STREAMS extends [Stream<any>, ...Stream<any>[]]>(\n ...streams: STREAMS\n): (stream: Stream<VALUE>) => Stream<VALUE | ValueOf<STREAMS[number]>> {\n return (stream: Stream<VALUE>): Stream<VALUE | ValueOf<STREAMS[number]>> =>\n new Stream<VALUE | ValueOf<STREAMS[number]>>(async function* () {\n const allStreams = [stream, ...streams];\n const queue: (VALUE | ValueOf<STREAMS[number]>)[] = [];\n let resolver: Function | undefined;\n\n const cleanups = allStreams.map((s) =>\n s.listen((value) => {\n queue.push(value);\n resolver?.();\n })\n );\n\n try {\n while (true) {\n if (queue.length) {\n yield queue.shift()!;\n } else {\n await new Promise((resolve) => (resolver = resolve));\n }\n }\n } finally {\n cleanups.forEach((cleanup) => cleanup());\n }\n });\n}\n",
9
- "import { Stream } from \"../stream.ts\";\nimport { map } from \"./map.ts\";\n\n/**\n * Flatten arrays in a stream, converting 1 array event into N individual events.\n *\n * @template VALUE - The type of values in the stream (should be arrays)\n * @template DEPTH - The depth of flattening (0 = one level, 1 = two levels, etc.)\n *\n * @param depth - How many levels deep to flatten (default: 0 = one level)\n *\n * @returns A transformer that flattens array values into individual events\n *\n * @example\n * // Basic flattening - 1 array → N events\n * const arrayStream = new Stream<number[]>();\n * const individualNumbers = arrayStream.pipe(flat());\n *\n * arrayStream.push([1, 2, 3]); // Emits: 1, 2, 3 as separate events\n *\n * @example\n * // Deep flattening\n * const deepArrays = new Stream<number[][]>();\n * const flattened = deepArrays.pipe(flat(1)); // Flatten 2 levels\n *\n * deepArrays.push([[1, 2], [3, 4]]);\n * // Emits: 1, 2, 3, 4 as separate events\n *\n */\nexport function flat<VALUE, DEPTH extends number = 0>(\n depth: DEPTH = 0 as DEPTH\n): (stream: Stream<VALUE>) => Stream<FlatArray<VALUE, DEPTH>> {\n return (stream: Stream<VALUE>): Stream<FlatArray<VALUE, DEPTH>> => {\n return new Stream<FlatArray<VALUE, DEPTH>>(async function* () {\n for await (const value of stream) {\n if (Array.isArray(value)) {\n const values = value.flat(depth);\n for (let i = 0; i < values.length; i++) {\n yield values[i]!;\n }\n } else {\n yield value as FlatArray<VALUE, DEPTH>;\n }\n }\n });\n };\n}\n",
10
- "import { Stream } from \"../stream.ts\";\n\n/**\n * A reactive List that provides array-like functionality with stream-based mutation events.\n * Emits events when items are inserted, deleted, or the list is cleared.\n * Supports negative indexing with modulo wrapping.\n * @template VALUE - The type of values stored in the list\n *\n * @example\n * ```typescript\n * const todos = new List<string>();\n *\n * // Listen to insertions\n * todos.insert.listen(([index, item]) => {\n * console.log(`Added \"${item}\" at index ${index}`);\n * });\n *\n * // Listen to deletions\n * todos.delete.listen(([index, item]) => {\n * console.log(`Removed \"${item}\" from index ${index}`);\n * });\n *\n * todos.insert(0, \"Buy milk\"); //Added \"Buy milk\" at index 0\n * todos.insert(1, \"Walk dog\"); //Added \"Walk dog\" at index 1\n * todos.insert(-1, \"kechma haja\"); //Added \"kechma haja\" at index 2\n * todos[0] = \"Buy organic milk\"; // Added \"Buy organic milk\" at index 0\n * ```\n */\nexport class List<VALUE> implements Iterable<VALUE> {\n private _items: VALUE[] = [];\n private _insertStream?: Stream<[number, VALUE]>;\n private _deleteStream?: Stream<[number, VALUE]>;\n private _clearStream?: Stream<void>;\n\n [index: number]: VALUE | undefined;\n\n /**\n * Inserts a value at the specified index and emits the insertion event.\n * Negative indices are handled specially for insertion positioning.\n *\n * @example\n * ```typescript\n * const list = new List([1, 2, 3]);\n * list.insert.listen(([index, value]) => console.log(`Inserted ${value} at ${index}`));\n *\n * list.insert(1, 99); // Inserted 99 at 1 → [1, 99, 2, 3]\n * list.insert(-1, 88); // Insert at end → [1, 99, 2, 3, 88]\n * ```\n */\n declare insert: ((index: number, value: VALUE) => this) & Stream<[number, VALUE]>;\n\n /**\n * Deletes a value at the specified index and emits the deletion event.\n * Returns the deleted value or undefined if index is invalid.\n *\n * @example\n * ```typescript\n * const list = new List(['a', 'b', 'c']);\n * list.delete.listen(([index, value]) => console.log(`Deleted ${value} from ${index}`));\n *\n * const deleted = list.delete(1); // Deleted b from 1\n * console.log(deleted); // 'b'\n * ```\n */\n declare delete: ((index: number) => VALUE | undefined) & Stream<[number, VALUE]>;\n\n /**\n * Clears all items from the list and emits the clear event.\n * Only emits if the list was not already empty.\n *\n * @example\n * ```typescript\n * const list = new List([1, 2, 3]);\n * list.clear.listen(() => console.log('List cleared'));\n *\n * list.clear(); // List cleared\n * list.clear(); // No emission (already empty)\n * ```\n */\n declare clear: (() => void) & Stream<void>;\n\n /**\n * Creates a new reactive List.\n *\n * @param items - Optional iterable of initial items\n *\n * @example\n * ```typescript\n * // Empty list\n * const list = new List<number>();\n *\n * // With initial items\n * const todos = new List(['Buy milk', 'Walk dog']);\n *\n * // Listen to changes\n * todos.insert.listen(([index, item]) => updateUI(index, item));\n * todos.delete.listen(([index, item]) => removeFromUI(index));\n *\n * // Index access with modulo wrapping\n * console.log(todos[0]); // 'Buy milk'\n * console.log(todos[-1]); // 'Walk dog' (last item)\n * ```\n */\n constructor(items?: Iterable<VALUE>) {\n if (items) this._items = [...items];\n\n const self = this;\n\n function normalizeIndex(index: number, length: number): number {\n if (length === 0) return 0;\n return index < 0 ? ((index % length) + length) % length : index % length;\n }\n\n this.insert = new Proxy(\n (index: number, value: VALUE): this => {\n const actualIndex =\n index < 0 ? Math.max(0, self._items.length + index + 1) : Math.min(index, self._items.length);\n self._items.splice(actualIndex, 0, value);\n self._insertStream?.push([actualIndex, value]);\n return proxy;\n },\n {\n get(target, prop) {\n if (prop in target) return (target as any)[prop];\n if (!self._insertStream) self._insertStream = new Stream();\n return (self._insertStream as any)[prop];\n },\n }\n ) as any;\n this.delete = new Proxy(\n (index: number): VALUE | undefined => {\n if (index < 0 || index >= self._items.length) return undefined;\n const value = self._items.splice(index, 1)[0]!;\n self._deleteStream?.push([index, value]);\n return value;\n },\n {\n get(target, prop) {\n if (prop in target) return (target as any)[prop];\n if (!self._deleteStream) self._deleteStream = new Stream();\n return (self._deleteStream as any)[prop];\n },\n }\n ) as any;\n\n this.clear = new Proxy(\n (): void => {\n if (self._items.length > 0) {\n self._items.length = 0;\n self._clearStream?.push();\n }\n },\n {\n get(target, prop) {\n if (prop in target) return (target as any)[prop];\n if (!self._clearStream) self._clearStream = new Stream();\n return (self._clearStream as any)[prop];\n },\n }\n ) as any;\n\n const proxy = new Proxy(this, {\n get(target, prop) {\n if (typeof prop === \"string\" && /^-?\\d+$/.test(prop)) {\n const index = parseInt(prop);\n if (target._items.length === 0) return undefined;\n const actualIndex = normalizeIndex(index, target._items.length);\n return target._items[actualIndex];\n }\n return (target as any)[prop];\n },\n\n set(target, prop, value) {\n if (typeof prop === \"string\" && /^-?\\d+$/.test(prop)) {\n const index = parseInt(prop);\n\n if (target._items.length === 0) {\n // Empty array: any index mutation adds first element at index 0\n target._items.push(value);\n target._insertStream?.push([0, value]);\n return true;\n }\n\n const actualIndex = normalizeIndex(index, target._items.length);\n const oldValue = target._items[actualIndex];\n\n if (oldValue !== value) {\n target._items[actualIndex] = value;\n target._insertStream?.push([actualIndex, value]);\n }\n return true;\n }\n (target as any)[prop] = value;\n return true;\n },\n });\n\n return proxy;\n }\n\n /**\n * Gets the value at the specified index without modulo wrapping.\n *\n * @param index - The index to access\n * @returns The value at the index or undefined\n *\n * @example\n * ```typescript\n * const list = new List([10, 20, 30]);\n * console.log(list.get(1)); // 20\n * console.log(list.get(5)); // undefined\n * ```\n */\n get(index: number): VALUE | undefined {\n return this._items[index];\n }\n\n /**\n * Gets the current length of the list.\n *\n * @example\n * ```typescript\n * const list = new List([1, 2, 3]);\n * console.log(list.length); // 3\n *\n * list.insert(0, 0);\n * console.log(list.length); // 4\n * ```\n */\n get length(): number {\n return this._items.length;\n }\n /**\n * Returns an iterator for the list values.\n *\n * @example\n * ```typescript\n * const list = new List([1, 2, 3]);\n * for (const value of list.values()) {\n * console.log(value); // 1, 2, 3\n * }\n * ```\n */\n values(): IterableIterator<VALUE> {\n return this._items[Symbol.iterator]();\n }\n /**\n * Makes the list iterable.\n *\n * @example\n * ```typescript\n * const list = new List(['a', 'b', 'c']);\n * for (const item of list) {\n * console.log(item); // 'a', 'b', 'c'\n * }\n *\n * const array = [...list]; // ['a', 'b', 'c']\n * ```\n */\n [Symbol.iterator](): IterableIterator<VALUE> {\n return this._items[Symbol.iterator]();\n }\n}\n",
11
- "import { Stream } from \"../stream.ts\";\n\n/**\n * A reactive Map that extends the native Map with stream-based mutation events.\n * Emits events when entries are set, deleted, or the map is cleared.\n *\n * @template KEY - The type of keys in the map\n * @template VALUE - The type of values in the map\n *\n * @example\n * ```typescript\n * const cache = new Map<string, any>();\n *\n * // Listen to cache updates\n * cache.set.listen(([key, value]) => {\n * console.log(`Cache updated: ${key} = ${value}`);\n * });\n *\n * // Listen to cache evictions\n * cache.delete.listen(([key, value]) => {\n * console.log(`Cache evicted: ${key}`);\n * });\n *\n * cache.set('user:123', { name: 'John' });\n * cache.delete('user:123');\n * ```\n */\nexport class Map<KEY, VALUE> extends globalThis.Map<KEY, VALUE> {\n protected _setStream?: Stream<[KEY, VALUE]>;\n protected _deleteStream?: Stream<[KEY, VALUE]>;\n protected _clearStream?: Stream<void>;\n\n /**\n * Sets a key-value pair in the map and emits the entry to listeners.\n * Only emits if the value actually changes (not same key-value pair).\n *\n * @example\n * ```typescript\n * const config = new Map<string, string>();\n * config.set.listen(([key, value]) => console.log(`Set: ${key}=${value}`));\n *\n * config.set('theme', 'dark'); // Set: theme=dark\n * config.set('theme', 'dark'); // No emission (same value)\n * config.set('theme', 'light'); // Set: theme=light\n * ```\n */\n declare set: ((key: KEY, value: VALUE) => this) & Stream<[KEY, VALUE]>;\n\n /**\n * Deletes a key from the map and emits the deleted entry to listeners.\n * Only emits if the key was actually deleted (existed in map).\n *\n * @example\n * ```typescript\n * const users = new Map([['alice', { age: 30 }], ['bob', { age: 25 }]]);\n * users.delete.listen(([key, value]) => console.log(`Removed: ${key}`));\n *\n * users.delete('alice'); // Removed: alice\n * users.delete('charlie'); // No emission (didn't exist)\n * ```\n */\n declare delete: ((key: KEY) => boolean) & Stream<[KEY, VALUE]>;\n\n /**\n * Clears all entries from the map and emits to listeners.\n * Only emits if the map was not already empty.\n *\n * @example\n * ```typescript\n * const store = new Map([['a', 1], ['b', 2]]);\n * store.clear.listen(() => console.log('Store cleared'));\n *\n * store.clear(); // Store cleared\n * store.clear(); // No emission (already empty)\n * ```\n */\n declare clear: (() => void) & Stream<void>;\n\n /**\n * Creates a new reactive Map.\n *\n * @param entries - Optional iterable of initial key-value pairs\n *\n * @example\n * ```typescript\n * // Empty map\n * const cache = new Map<string, any>();\n *\n * // With initial entries\n * const config = new Map([\n * ['theme', 'dark'],\n * ['lang', 'en']\n * ]);\n *\n * // Listen to changes\n * config.set.listen(([key, value]) => saveConfig(key, value));\n * config.delete.listen(([key]) => removeConfig(key));\n * ```\n */\n constructor(entries?: Iterable<[KEY, VALUE]>) {\n super(entries);\n\n const self = this;\n\n this.set = new Proxy(\n (key: KEY, value: VALUE): this => {\n if (globalThis.Map.prototype.has.call(self, key) && globalThis.Map.prototype.get.call(self, key) === value)\n return self;\n globalThis.Map.prototype.set.call(self, key, value);\n self._setStream?.push([key, value]);\n return self;\n },\n {\n get(target, prop) {\n if (prop in target) return (target as any)[prop];\n if (!self._setStream) self._setStream = new Stream();\n return (self._setStream as any)[prop];\n },\n }\n ) as any;\n\n this.delete = new Proxy(\n (key: KEY): boolean => {\n if (!globalThis.Map.prototype.has.call(self, key)) return false;\n const value = globalThis.Map.prototype.get.call(self, key);\n globalThis.Map.prototype.delete.call(self, key);\n self._deleteStream?.push([key, value]);\n return true;\n },\n {\n get(target, prop) {\n if (prop in target) return (target as any)[prop];\n if (!self._deleteStream) self._deleteStream = new Stream();\n return (self._deleteStream as any)[prop];\n },\n }\n ) as any;\n\n this.clear = new Proxy(\n (): void => {\n if (self.size > 0) {\n globalThis.Map.prototype.clear.call(self);\n self._clearStream?.push();\n }\n },\n {\n get(target, prop) {\n if (prop in target) return (target as any)[prop];\n if (!self._clearStream) self._clearStream = new Stream();\n return (self._clearStream as any)[prop];\n },\n }\n ) as any;\n }\n}\n",
12
- "import { Stream } from \"../stream.ts\";\n\n/**\n * A reactive Set that extends the native Set with stream-based mutation events.\n * Emits events when items are added, deleted, or the set is cleared.\n *\n * @template VALUE - The type of values stored in the set\n *\n * @example\n * ```typescript\n * const activeUsers = new Set<string>();\n *\n * // Listen to additions\n * activeUsers.add.listen(userId => {\n * console.log(`User ${userId} came online`);\n * });\n *\n * // Listen to deletions\n * activeUsers.delete.listen(userId => {\n * console.log(`User ${userId} went offline`);\n * });\n *\n * activeUsers.add('alice'); // User alice came online\n * activeUsers.delete('alice'); // User alice went offline\n * ```\n */\nexport class Set<VALUE> extends globalThis.Set<VALUE> {\n protected _addStream?: Stream<VALUE>;\n protected _deleteStream?: Stream<VALUE>;\n protected _clearStream?: Stream<void>;\n\n /**\n * Adds a value to the set and emits the value to listeners.\n * Only emits if the value is actually added (not a duplicate).\n *\n * @example\n * ```typescript\n * const tags = new Set<string>();\n * tags.add.listen(tag => console.log('Added:', tag));\n *\n * tags.add('javascript'); // Added: javascript\n * tags.add('javascript'); // No emission (duplicate)\n * ```\n */\n declare add: ((value: VALUE) => this) & Stream<VALUE>;\n\n /**\n * Deletes a value from the set and emits the value to listeners.\n * Only emits if the value was actually deleted (existed in set).\n *\n * @example\n * ```typescript\n * const items = new Set(['a', 'b', 'c']);\n * items.delete.listen(item => console.log('Removed:', item));\n *\n * items.delete('b'); // Removed: b\n * items.delete('x'); // No emission (didn't exist)\n * ```\n */\n declare delete: ((value: VALUE) => boolean) & Stream<VALUE>;\n\n /**\n * Clears all values from the set and emits to listeners.\n * Only emits if the set was not already empty.\n *\n * @example\n * ```typescript\n * const cache = new Set([1, 2, 3]);\n * cache.clear.listen(() => console.log('Cache cleared'));\n *\n * cache.clear(); // Cache cleared\n * cache.clear(); // No emission (already empty)\n * ```\n */\n declare clear: (() => void) & Stream<void>;\n\n /**\n * Creates a new reactive Set.\n *\n * @param values - Optional iterable of initial values\n *\n * @example\n * ```typescript\n * // Empty set\n * const tags = new Set<string>();\n *\n * // With initial values\n * const colors = new Set(['red', 'green', 'blue']);\n *\n * // Listen to changes\n * colors.add.listen(color => updateUI(color));\n * colors.delete.listen(color => removeFromUI(color));\n * ```\n */\n constructor(values?: Iterable<VALUE>) {\n super(values);\n\n const self = this;\n\n this.add = new Proxy(\n (value: VALUE): this => {\n if (globalThis.Set.prototype.has.call(self, value)) return self;\n globalThis.Set.prototype.add.call(self, value);\n self._addStream?.push(value);\n return self;\n },\n {\n get(target, prop) {\n if (prop in target) return (target as any)[prop];\n if (!self._addStream) self._addStream = new Stream<VALUE>();\n return (self._addStream as any)[prop];\n },\n }\n ) as any;\n\n this.delete = new Proxy(\n (value: VALUE): boolean => {\n if (!globalThis.Set.prototype.has.call(self, value)) return false;\n globalThis.Set.prototype.delete.call(self, value);\n self._deleteStream?.push(value);\n return true;\n },\n {\n get(target, prop) {\n if (prop in target) return (target as any)[prop];\n if (!self._deleteStream) self._deleteStream = new Stream<VALUE>();\n return (self._deleteStream as any)[prop];\n },\n }\n ) as any;\n\n this.clear = new Proxy(\n (): void => {\n if (self.size > 0) {\n globalThis.Set.prototype.clear.call(self);\n self._clearStream?.push();\n }\n },\n {\n get(target, prop) {\n if (prop in target) return (target as any)[prop];\n if (!self._clearStream) self._clearStream = new Stream<void>();\n return (self._clearStream as any)[prop];\n },\n }\n ) as any;\n }\n}\n",
13
- "import { Stream } from \"../stream.ts\";\n\n/**\n * A reactive state container that extends Stream to provide stateful value management.\n *\n * @template VALUE - The type of the state value\n *\n * @example\n * ```typescript\n * // Basic state\n * const counter = new State(0);\n * counter.listen(value => console.log('Counter:', value));\n * counter.value = 5; // Counter: 5\n *\n * // Complex state\n * interface User { id: string; name: string; }\n * const user = new State<User | null>(null);\n *\n * user.listen(u => console.log('User:', u?.name || 'None'));\n * user.value = { id: '1', name: 'Alice' }; // User: Alice\n * ```\n */\nexport class State<VALUE> extends Stream<VALUE> {\n protected _value: VALUE;\n\n /**\n * Creates a new State with an initial value.\n *\n * @param initialValue - The initial state value\n *\n * @example\n * ```typescript\n * const count = new State(0);\n * const theme = new State<'light' | 'dark'>('light');\n * const user = new State<User | null>(null);\n * ```\n */\n constructor(initialValue: VALUE) {\n super();\n this._value = initialValue;\n }\n /**\n * Updates the state with one or more values sequentially.\n * Each value triggers listeners and updates the current state.\n *\n * @param values - Values to set as state\n *\n * @example\n * ```typescript\n * const state = new State(0);\n * state.listen(v => console.log(v));\n *\n * state.push(1, 2, 3); // Logs: 1, 2, 3\n * console.log(state.value); // 3\n * ```\n */\n override push(...values: VALUE[]): void {\n for (const value of values) {\n this.value = value;\n }\n }\n /**\n * Gets the current state value.\n *\n * @example\n * ```typescript\n * const state = new State('hello');\n * console.log(state.value); // 'hello'\n * ```\n */\n get value(): VALUE {\n return this._value;\n }\n /**\n * Sets the current state value and notifies all listeners.\n *\n * @param value - The new state value\n *\n * @example\n * ```typescript\n * const state = new State(0);\n * state.listen(v => console.log('New value:', v));\n *\n * state.value = 42; // New value: 42\n * state.value = 100; // New value: 100\n * ```\n */\n set value(value: VALUE) {\n this._value = value;\n super.push(value);\n }\n}\n"
5
+ "export type ValueOf<STREAM> = STREAM extends Stream<infer VALUE> ? VALUE : never;\nexport type FunctionGenerator<VALUE> = () => AsyncGenerator<VALUE, void>;\n/**\n * A reactive streaming library that provides async-first data structures with built-in event streams.\n *\n * @template VALUE - The type of values that flow through the stream\n *\n * @example\n * ```typescript\n * // Basic usage\n * const stream = new Stream<number>();\n * stream.listen(value => console.log(value));\n * stream.push(1, 2, 3);\n *\n * // With async generator\n * const timerStream = new Stream(async function* () {\n * let count = 0;\n * while (count < 5) {\n * yield count++;\n * await new Promise(resolve => setTimeout(resolve, 1000));\n * }\n * });\n *\n * // Async iteration\n * for await (const value of stream) {\n * console.log(value);\n * if (value === 10) break;\n * }\n * ```\n *\n * @example\n * // 📦 COPY-PASTE TRANSFORMERS LIBRARY - Essential transformers for immediate use\n *\n * // FILTERING TRANSFORMERS\n * const simpleFilter = <T>(predicate: (value: T) => boolean | Promise<boolean>) =>\n * filter<T, {}>({}, async (_, value) => {\n * const shouldPass = await predicate(value);\n * return [shouldPass, {}];\n * });\n *\n * const take = <T>(n: number) =>\n * filter<T, { count: number }>({ count: 0 }, (state, value) => {\n * if (state.count >= n) return;\n * return [true, { count: state.count + 1 }];\n * });\n *\n * const distinct = <T>() =>\n * filter<T, { seen: Set<T> }>({ seen: new Set() }, (state, value) => {\n * if (state.seen.has(value)) return [false, state];\n * state.seen.add(value);\n * return [true, state];\n * });\n *\n * const tap = <T>(fn: (value: T) => void | Promise<void>) =>\n * filter<T, {}>({}, async (_, value) => {\n * await fn(value);\n * return [true, {}];\n * });\n *\n * // MAPPING TRANSFORMERS\n * const simpleMap = <T, U>(fn: (value: T) => U | Promise<U>) =>\n * map<T, {}, U>({}, async (_, value) => {\n * const result = await fn(value);\n * return [result, {}];\n * });\n *\n * const withIndex = <T>() =>\n * map<T, { index: number }, { value: T; index: number }>(\n * { index: 0 },\n * (state, value) => [\n * { value, index: state.index },\n * { index: state.index + 1 }\n * ]\n * );\n *\n * const delay = <T>(ms: number) =>\n * map<T, {}, T>({}, async (_, value) => {\n * await new Promise(resolve => setTimeout(resolve, ms));\n * return [value, {}];\n * });\n *\n * const scan = <T, U>(fn: (acc: U, value: T) => U, initial: U) =>\n * map<T, { acc: U }, U>({ acc: initial }, (state, value) => {\n * const newAcc = fn(state.acc, value);\n * return [newAcc, { acc: newAcc }];\n * });\n *\n * // STATE CONVERTER\n * const toState = <T>(initialValue: T) => (stream: Stream<T>) => {\n * return new State(initialValue, stream);\n * };\n *\n * // Usage: stream.pipe(simpleFilter(x => x > 0)).pipe(take(5)).pipe(toState(0));\n */\nexport class Stream<VALUE = unknown> implements AsyncIterable<VALUE> {\n protected _listeners: Set<(value: VALUE) => void> = new Set<(value: VALUE) => void>();\n protected _generatorFn: FunctionGenerator<VALUE> | undefined;\n protected _generator: AsyncGenerator<VALUE, void> | undefined;\n protected _listenerAdded: Stream<void> | undefined;\n protected _listenerRemoved: Stream<void> | undefined;\n\n /**\n * Creates a new Stream instance.\n *\n * @param generatorFn - Optional async generator function to produce values you can use it for creating stream with custom transformation\n *\n * @see {@link Stream} - Complete copy-paste transformers library\n *\n * @example\n * ```typescript\n * // Empty stream\n * const stream = new Stream<string>();\n *\n * // Stream with generator\n * const countdown = new Stream(async function* () {\n * for (let i = 5; i > 0; i--) {\n * yield i;\n * await new Promise(resolve => setTimeout(resolve, 1000));\n * }\n * });\n *\n * // Stream with custom transformer\n * function filter<VALUE>(source:Stream<VALUE>,predicate:(value:VALUE) => boolean):Stream<VALUE>{\n * return new Stream<VALUE>(async function* () {\n * for await (const value of source) {\n * if (predicate(value)) yield value ;\n * }\n * });\n * }\n * const source = new Stream<number>();\n * const even = filter(source,v=> v % 2 === 0)\n * even.listen(console.log);\n * source.push(1, 2, 3, 4); // 2,4\n * ```\n */\n constructor();\n constructor(stream: FunctionGenerator<VALUE> | Stream<VALUE>);\n constructor(stream?: FunctionGenerator<VALUE> | Stream<VALUE>) {\n this._generatorFn = stream instanceof Stream ? () => stream[Symbol.asyncIterator]() : stream;\n }\n\n /**\n * Returns true if the stream has active listeners.\n *\n * @see {@link Stream} - Complete copy-paste transformers library\n *\n * @example\n * ```typescript\n * const stream = new Stream<number>();\n * console.log(stream.hasListeners); // false\n *\n * const cleanup = stream.listen(value => console.log(value));\n * console.log(stream.hasListeners); // true\n *\n * cleanup();\n * console.log(stream.hasListeners); // false\n * ```\n */\n get hasListeners(): boolean {\n return this._listeners.size > 0;\n }\n\n /**\n * Stream that emits when a listener is added.\n *\n * @see {@link Stream} - Complete copy-paste transformers library\n *\n * @example\n * ```typescript\n * const stream = new Stream<number>();\n * stream.listenerAdded.listen(() => console.log('Listener added'));\n *\n * stream.listen(value => console.log(value)); // Triggers 'Listener added'\n * ```\n */\n get listenerAdded(): Stream<void> {\n if (!this._listenerAdded) this._listenerAdded = new Stream<void>();\n return this._listenerAdded;\n }\n\n /**\n * Stream that emits when a listener is removed.\n *\n * @see {@link Stream} - Complete copy-paste transformers library\n *\n * @example\n * ```typescript\n * const stream = new Stream<number>();\n * stream.listenerRemoved.listen(() => console.log('Listener removed'));\n *\n * const cleanup = stream.listen(value => console.log(value));\n * cleanup(); // Triggers 'Listener removed'\n * ```\n */\n get listenerRemoved(): Stream<void> {\n if (!this._listenerRemoved) this._listenerRemoved = new Stream<void>();\n return this._listenerRemoved;\n }\n async *[Symbol.asyncIterator](): AsyncGenerator<VALUE, void> {\n const queue: VALUE[] = [];\n let resolver: Function | undefined;\n\n const abort = this.listen((value) => {\n queue.push(value);\n resolver?.();\n });\n\n try {\n while (true) {\n if (queue.length) yield queue.shift()!;\n else await new Promise<void>((resolve) => (resolver = resolve));\n }\n } finally {\n abort();\n queue.length = 0;\n resolver = undefined;\n return;\n }\n }\n\n /**\n * Pushes one or more values to all listeners.\n *\n * @see {@link Stream} - Complete copy-paste transformers library\n *\n * @param value - The first value to push\n * @param values - Additional values to push\n *\n * @example\n * ```typescript\n * const stream = new Stream<number>();\n * stream.listen(value => console.log('Received:', value));\n *\n * stream.push(1); // Received: 1\n * stream.push(2, 3, 4); // Received: 2, Received: 3, Received: 4\n * ```\n */\n push(value: VALUE, ...values: VALUE[]): void {\n values.unshift(value);\n for (const value of values) {\n for (const listener of this._listeners) {\n listener(value);\n }\n }\n }\n\n /**\n * Adds a listener to the stream.\n *\n * @param listener - Function to call when values are pushed\n * @param signal - Optional AbortSignal for cleanup\n * @returns Cleanup function to remove the listener\n *\n * @see {@link Stream} - Complete copy-paste transformers library\n *\n * @example\n * ```typescript\n * const stream = new Stream<string>();\n *\n * // Basic listener\n * const cleanup = stream.listen(value => console.log(value));\n *\n * // With AbortSignal\n * const controller = new AbortController();\n * stream.listen(value => console.log(value), controller.signal);\n * controller.abort(); // Removes listener\n *\n * // Manual cleanup\n * cleanup();\n * ```\n */\n listen(listener: (value: VALUE) => void, signal?: AbortSignal | Stream<any>): () => void {\n const self = this;\n let signalAbort: Function | undefined;\n\n if (signal instanceof AbortSignal) {\n if (signal?.aborted) return () => {};\n signal?.addEventListener(\"abort\", abort);\n signalAbort = () => signal?.removeEventListener(\"abort\", abort);\n } else {\n signalAbort = signal?.listen(abort);\n }\n\n self._listeners.add(listener);\n\n self._listenerAdded?.push();\n\n if (self._generatorFn && self._listeners.size === 1) {\n self._generator = self._generatorFn();\n (async () => {\n for await (const value of self._generator!) {\n self.push(value);\n }\n })();\n }\n return abort;\n function abort(): void {\n self._listeners.delete(listener);\n self._listenerRemoved?.push();\n if (self._listeners.size === 0) {\n self._generator?.return();\n self._generator = undefined;\n }\n signalAbort?.();\n }\n }\n\n /**\n * Promise-like interface that resolves with the next value.\n *\n * @param onfulfilled - Optional transformation function\n * @returns Promise that resolves with the first value\n *\n * @see {@link Stream} - Complete copy-paste transformers library\n *\n * @example\n * ```typescript\n * const stream = new Stream<number>();\n *\n * setTimeout(()=>{\n * stream.push(5);\n * })\n * // Wait for first value\n * const firstValue = await stream; // Resolves promises with 5\n *\n *\n * ```\n */\n then(onfulfilled?: ((value: VALUE) => VALUE | PromiseLike<VALUE>) | null): Promise<VALUE> {\n return new Promise<VALUE>((resolve) => {\n const abort = this.listen((value) => {\n resolve(value);\n abort();\n });\n }).then(onfulfilled);\n }\n\n /**\n * Applies a transformer function to this stream, enabling functional composition.\n *\n * @param transformer - Function that takes a stream and returns any output type\n * @returns The result of the transformer function\n *\n * @see {@link Stream} - Complete copy-paste transformers library\n *\n * @example\n * ```typescript\n * const numbers = new Stream<number>();\n *\n * // Chain transformers\n * const result = numbers\n * .pipe(filter({}, (_, n) => [n > 0, {}]))\n * .pipe(map({}, (_, n) => [n * 2, {}]))\n * .pipe(toState(0));\n *\n * // Custom transformer\n * const throttle = <T>(ms: number) => (stream: Stream<T>) =>\n * new Stream<T>(async function* () {\n * let lastEmit = 0;\n * for await (const value of stream) {\n * const now = Date.now();\n * if (now - lastEmit >= ms) {\n * yield value;\n * lastEmit = now;\n * }\n * }\n * });\n *\n * // Transform to any type\n * const stringResult = numbers.pipe(throttle(1000));\n * const stateResult = numbers.pipe(toState(0));\n * ```\n */\n pipe<OUTPUT extends Stream<any>>(transformer: (stream: this) => OUTPUT): OUTPUT {\n return transformer(this);\n }\n}\n",
6
+ "import { Stream } from \"../stream.ts\";\n\n/**\n * Adaptive filter transformer that maintains state and can terminate streams.\n *\n * @template VALUE - The type of values flowing through the stream\n * @template STATE - The type of the internal state object\n *\n * @param initialState - Initial state object for the transformer\n * @param predicate - Function that determines if a value should pass through\n * - Returns `[boolean, newState]` to continue with updated state\n * - Returns `void` or `undefined` to terminate the stream\n * - Can be async for complex filtering logic\n *\n * @returns A transformer function that can be used with `.pipe()`\n *\n * @see {@link Stream} - Complete copy-paste transformers library\n *\n * @example\n * // Simple filtering\n * stream.pipe(filter({}, (_, value) => [value > 0, {}]))\n *\n * @example\n * // Async filtering\n * stream.pipe(\n * filter({}, async (_, value) => {\n * const valid = await validate(value);\n * return [valid, {}];\n * })\n * )\n *\n\n *\n */\nexport function filter<VALUE, STATE extends Record<string, unknown> = {}>(\n initialState: STATE,\n predicate: (state: STATE, value: VALUE) => [boolean, STATE] | void | Promise<[boolean, STATE] | void>\n): (stream: Stream<VALUE>) => Stream<VALUE> {\n return (stream: Stream<VALUE>): Stream<VALUE> =>\n new Stream<VALUE>(async function* () {\n let currentState = initialState;\n\n for await (const value of stream) {\n const result = await predicate(currentState, value);\n if (!result) return;\n const [emit, state] = result;\n currentState = state;\n if (emit) {\n yield value;\n }\n }\n });\n}\n",
7
+ "import { State } from \"../reactive/state.ts\";\nimport { Stream } from \"../stream.ts\";\n\n/**\n * Adaptive map transformer that transforms values while maintaining state.\n *\n * @template VALUE - The type of input values\n * @template STATE - The type of the internal state object\n * @template MAPPED - The type of output values after transformation\n *\n * @param initialState - Initial state object for the transformer\n * @param predicate - Function that transforms values and updates state\n * - Must return `[transformedValue, newState]`\n * - Can be async for complex transformations\n * - Preserves order even with async operations\n *\n * @returns A transformer function that can be used with `.pipe()`\n * \n * @see {@link Stream} - Complete copy-paste transformers library\n *\n * @example\n * // Simple transformation\n * stream.pipe(map({}, (_, value) => [value * 2, {}]))\n *\n * @example\n * // Async transformation\n * stream.pipe(\n * map({}, async (_, value) => {\n * const result = await process(value);\n * return [result, {}];\n * })\n * )\n *\n\n *\n */\nexport function map<VALUE, STATE extends Record<string, unknown>, MAPPED>(\n initialState: STATE,\n predicate: (state: STATE, value: VALUE) => [MAPPED, STATE] | Promise<[MAPPED, STATE]>\n): (stream: Stream<VALUE>) => Stream<MAPPED> {\n return (stream: Stream<VALUE>): Stream<MAPPED> =>\n new Stream<MAPPED>(async function* () {\n let currentState = initialState;\n for await (const value of stream) {\n const [mapped, state] = await predicate(currentState, value);\n currentState = state;\n yield mapped;\n }\n });\n}\n",
8
+ "import { Stream } from \"../stream.ts\";\n\ntype ValueOf<STREAM> = STREAM extends Stream<infer VALUE> ? VALUE : never;\n\n/**\n * Merge multiple streams into a single stream with temporal ordering.\n * \n * @template VALUE - The type of values from the source stream\n * @template STREAMS - Tuple type of additional streams to merge\n * \n * @param streams - Additional streams to merge with the source stream\n * \n * @returns A transformer that merges all streams into one with union types\n *\n * @see {@link Stream} - Complete copy-paste transformers library\n *\n * @example\n * // Basic merge with type safety\n * const numbers = new Stream<number>();\n * const strings = new Stream<string>();\n * const merged = numbers.pipe(merge(strings));\n * // Type: Stream<number | string>\n * \n * @example\n * // Multiple streams\n * const stream1 = new Stream<number>();\n * const stream2 = new Stream<string>();\n * const stream3 = new Stream<boolean>();\n * \n * const combined = stream1.pipe(merge(stream2, stream3));\n * // Type: Stream<number | string | boolean>\n * \n\n */\nexport function merge<VALUE, STREAMS extends [Stream<any>, ...Stream<any>[]]>(\n ...streams: STREAMS\n): (stream: Stream<VALUE>) => Stream<VALUE | ValueOf<STREAMS[number]>> {\n return (stream: Stream<VALUE>): Stream<VALUE | ValueOf<STREAMS[number]>> =>\n new Stream<VALUE | ValueOf<STREAMS[number]>>(async function* () {\n const allStreams = [stream, ...streams];\n const queue: (VALUE | ValueOf<STREAMS[number]>)[] = [];\n let resolver: Function | undefined;\n\n const cleanups = allStreams.map((s) =>\n s.listen((value) => {\n queue.push(value);\n resolver?.();\n })\n );\n\n try {\n while (true) {\n if (queue.length) {\n yield queue.shift()!;\n } else {\n await new Promise((resolve) => (resolver = resolve));\n }\n }\n } finally {\n cleanups.forEach((cleanup) => cleanup());\n }\n });\n}\n",
9
+ "import { Stream } from \"../stream.ts\";\nimport { map } from \"./map.ts\";\n\n/**\n * Flatten arrays in a stream, converting 1 array event into N individual events.\n *\n * @template VALUE - The type of values in the stream (should be arrays)\n * @template DEPTH - The depth of flattening (0 = one level, 1 = two levels, etc.)\n *\n * @param depth - How many levels deep to flatten (default: 0 = one level)\n *\n * @returns A transformer that flattens array values into individual events\n *\n * @see {@link Stream} - Complete copy-paste transformers library\n *\n * @example\n * // Basic flattening - 1 array → N events\n * const arrayStream = new Stream<number[]>();\n * const individualNumbers = arrayStream.pipe(flat());\n *\n * arrayStream.push([1, 2, 3]); // Emits: 1, 2, 3 as separate events\n *\n * @example\n * // Deep flattening\n * const deepArrays = new Stream<number[][]>();\n * const flattened = deepArrays.pipe(flat(1)); // Flatten 2 levels\n *\n * deepArrays.push([[1, 2], [3, 4]]);\n * // Emits: 1, 2, 3, 4 as separate events\n *\n */\nexport function flat<VALUE, DEPTH extends number = 0>(\n depth: DEPTH = 0 as DEPTH\n): (stream: Stream<VALUE>) => Stream<FlatArray<VALUE, DEPTH>> {\n return (stream: Stream<VALUE>): Stream<FlatArray<VALUE, DEPTH>> => {\n return new Stream<FlatArray<VALUE, DEPTH>>(async function* () {\n for await (const value of stream) {\n if (Array.isArray(value)) {\n const values = value.flat(depth);\n for (let i = 0; i < values.length; i++) {\n yield values[i]!;\n }\n } else {\n yield value as FlatArray<VALUE, DEPTH>;\n }\n }\n });\n };\n}\n",
10
+ "import { Stream } from \"../stream.ts\";\n\n/**\n * A reactive List that provides array-like functionality with stream-based mutation events.\n * Emits events when items are inserted, deleted, or the list is cleared.\n * Supports negative indexing with modulo wrapping.\n * @template VALUE - The type of values stored in the list\n *\n * @see {@link Stream} - Complete copy-paste transformers library\n *\n * @example\n * ```typescript\n * const todos = new List<string>();\n *\n * // Listen to insertions\n * todos.insert.listen(([index, item]) => {\n * console.log(`Added \"${item}\" at index ${index}`);\n * });\n *\n * // Listen to deletions\n * todos.delete.listen(([index, item]) => {\n * console.log(`Removed \"${item}\" from index ${index}`);\n * });\n *\n * todos.insert(0, \"Buy milk\"); //Added \"Buy milk\" at index 0\n * todos.insert(1, \"Walk dog\"); //Added \"Walk dog\" at index 1\n * todos.insert(-1, \"kechma haja\"); //Added \"kechma haja\" at index 2\n * todos[0] = \"Buy organic milk\"; // Added \"Buy organic milk\" at index 0\n * ```\n */\nexport class List<VALUE> implements Iterable<VALUE> {\n private _items: VALUE[] = [];\n private _insertStream?: Stream<[number, VALUE]>;\n private _deleteStream?: Stream<[number, VALUE]>;\n private _clearStream?: Stream<void>;\n\n [index: number]: VALUE | undefined;\n\n /**\n * Inserts a value at the specified index and emits the insertion event.\n * Negative indices are handled specially for insertion positioning.\n *\n * @see {@link Stream} - Complete copy-paste transformers library\n *\n * @example\n * ```typescript\n * const list = new List([1, 2, 3]);\n * list.insert.listen(([index, value]) => console.log(`Inserted ${value} at ${index}`));\n *\n * list.insert(1, 99); // Inserted 99 at 1 → [1, 99, 2, 3]\n * list.insert(-1, 88); // Insert at end → [1, 99, 2, 3, 88]\n * ```\n */\n declare insert: ((index: number, value: VALUE) => this) & Stream<[number, VALUE]>;\n\n /**\n * Deletes a value at the specified index and emits the deletion event.\n * Returns the deleted value or undefined if index is invalid.\n *\n * @see {@link Stream} - Complete copy-paste transformers library\n *\n * @example\n * ```typescript\n * const list = new List(['a', 'b', 'c']);\n * list.delete.listen(([index, value]) => console.log(`Deleted ${value} from ${index}`));\n *\n * const deleted = list.delete(1); // Deleted b from 1\n * console.log(deleted); // 'b'\n * ```\n */\n declare delete: ((index: number) => VALUE | undefined) & Stream<[number, VALUE]>;\n\n /**\n * Clears all items from the list and emits the clear event.\n * Only emits if the list was not already empty.\n *\n * @see {@link Stream} - Complete copy-paste transformers library\n *\n * @example\n * ```typescript\n * const list = new List([1, 2, 3]);\n * list.clear.listen(() => console.log('List cleared'));\n *\n * list.clear(); // List cleared\n * list.clear(); // No emission (already empty)\n * ```\n */\n declare clear: (() => void) & Stream<void>;\n\n /**\n * Creates a new reactive List.\n *\n * @param items - Optional iterable of initial items\n *\n * @see {@link Stream} - Complete copy-paste transformers library\n *\n * @example\n * ```typescript\n * // Empty list\n * const list = new List<number>();\n *\n * // With initial items\n * const todos = new List(['Buy milk', 'Walk dog']);\n *\n * // Listen to changes\n * todos.insert.listen(([index, item]) => updateUI(index, item));\n * todos.delete.listen(([index, item]) => removeFromUI(index));\n *\n * // Index access with modulo wrapping\n * console.log(todos[0]); // 'Buy milk'\n * console.log(todos[-1]); // 'Walk dog' (last item)\n * ```\n */\n constructor(items?: Iterable<VALUE>) {\n if (items) this._items = [...items];\n\n const self = this;\n\n function normalizeIndex(index: number, length: number): number {\n if (length === 0) return 0;\n return index < 0 ? ((index % length) + length) % length : index % length;\n }\n\n this.insert = new Proxy(\n (index: number, value: VALUE): this => {\n const actualIndex =\n index < 0 ? Math.max(0, self._items.length + index + 1) : Math.min(index, self._items.length);\n self._items.splice(actualIndex, 0, value);\n self._insertStream?.push([actualIndex, value]);\n return proxy;\n },\n {\n get(target, prop) {\n if (prop in target) return (target as any)[prop];\n if (!self._insertStream) self._insertStream = new Stream();\n return (self._insertStream as any)[prop];\n },\n }\n ) as any;\n this.delete = new Proxy(\n (index: number): VALUE | undefined => {\n if (index < 0 || index >= self._items.length) return undefined;\n const value = self._items.splice(index, 1)[0]!;\n self._deleteStream?.push([index, value]);\n return value;\n },\n {\n get(target, prop) {\n if (prop in target) return (target as any)[prop];\n if (!self._deleteStream) self._deleteStream = new Stream();\n return (self._deleteStream as any)[prop];\n },\n }\n ) as any;\n\n this.clear = new Proxy(\n (): void => {\n if (self._items.length > 0) {\n self._items.length = 0;\n self._clearStream?.push();\n }\n },\n {\n get(target, prop) {\n if (prop in target) return (target as any)[prop];\n if (!self._clearStream) self._clearStream = new Stream();\n return (self._clearStream as any)[prop];\n },\n }\n ) as any;\n\n const proxy = new Proxy(this, {\n get(target, prop) {\n if (typeof prop === \"string\" && /^-?\\d+$/.test(prop)) {\n const index = parseInt(prop);\n if (target._items.length === 0) return undefined;\n const actualIndex = normalizeIndex(index, target._items.length);\n return target._items[actualIndex];\n }\n return (target as any)[prop];\n },\n\n set(target, prop, value) {\n if (typeof prop === \"string\" && /^-?\\d+$/.test(prop)) {\n const index = parseInt(prop);\n\n if (target._items.length === 0) {\n // Empty array: any index mutation adds first element at index 0\n target._items.push(value);\n target._insertStream?.push([0, value]);\n return true;\n }\n\n const actualIndex = normalizeIndex(index, target._items.length);\n const oldValue = target._items[actualIndex];\n\n if (oldValue !== value) {\n target._items[actualIndex] = value;\n target._insertStream?.push([actualIndex, value]);\n }\n return true;\n }\n (target as any)[prop] = value;\n return true;\n },\n });\n\n return proxy;\n }\n\n /**\n * Gets the value at the specified index without modulo wrapping.\n *\n * @param index - The index to access\n * @returns The value at the index or undefined\n *\n * @see {@link Stream} - Complete copy-paste transformers library\n *\n * @example\n * ```typescript\n * const list = new List([10, 20, 30]);\n * console.log(list.get(1)); // 20\n * console.log(list.get(5)); // undefined\n * ```\n */\n get(index: number): VALUE | undefined {\n return this._items[index];\n }\n\n /**\n * Gets the current length of the list.\n *\n * @see {@link Stream} - Complete copy-paste transformers library\n *\n * @example\n * ```typescript\n * const list = new List([1, 2, 3]);\n * console.log(list.length); // 3\n *\n * list.insert(0, 0);\n * console.log(list.length); // 4\n * ```\n */\n get length(): number {\n return this._items.length;\n }\n /**\n * Returns an iterator for the list values.\n *\n * @see {@link Stream} - Complete copy-paste transformers library\n *\n * @example\n * ```typescript\n * const list = new List([1, 2, 3]);\n * for (const value of list.values()) {\n * console.log(value); // 1, 2, 3\n * }\n * ```\n */\n values(): IterableIterator<VALUE> {\n return this._items[Symbol.iterator]();\n }\n /**\n * Makes the list iterable.\n *\n * @see {@link Stream} - Complete copy-paste transformers library\n *\n * @example\n * ```typescript\n * const list = new List(['a', 'b', 'c']);\n * for (const item of list) {\n * console.log(item); // 'a', 'b', 'c'\n * }\n *\n * const array = [...list]; // ['a', 'b', 'c']\n * ```\n */\n [Symbol.iterator](): IterableIterator<VALUE> {\n return this._items[Symbol.iterator]();\n }\n}\n",
11
+ "import { Stream } from \"../stream.ts\";\n\n/**\n * A reactive Map that extends the native Map with stream-based mutation events.\n * Emits events when entries are set, deleted, or the map is cleared.\n *\n * @template KEY - The type of keys in the map\n * @template VALUE - The type of values in the map\n *\n * @see {@link Stream} - Complete copy-paste transformers library\n *\n * @example\n * ```typescript\n * const cache = new Map<string, any>();\n *\n * // Listen to cache updates\n * cache.set.listen(([key, value]) => {\n * console.log(`Cache updated: ${key} = ${value}`);\n * });\n *\n * // Listen to cache evictions\n * cache.delete.listen(([key, value]) => {\n * console.log(`Cache evicted: ${key}`);\n * });\n *\n * cache.set('user:123', { name: 'John' });\n * cache.delete('user:123');\n * ```\n */\nexport class Map<KEY, VALUE> extends globalThis.Map<KEY, VALUE> {\n protected _setStream?: Stream<[KEY, VALUE]>;\n protected _deleteStream?: Stream<[KEY, VALUE]>;\n protected _clearStream?: Stream<void>;\n\n /**\n * Sets a key-value pair in the map and emits the entry to listeners.\n * Only emits if the value actually changes (not same key-value pair).\n *\n * @see {@link Stream} - Complete copy-paste transformers library\n *\n * @example\n * ```typescript\n * const config = new Map<string, string>();\n * config.set.listen(([key, value]) => console.log(`Set: ${key}=${value}`));\n *\n * config.set('theme', 'dark'); // Set: theme=dark\n * config.set('theme', 'dark'); // No emission (same value)\n * config.set('theme', 'light'); // Set: theme=light\n * ```\n */\n declare set: ((key: KEY, value: VALUE) => this) & Stream<[KEY, VALUE]>;\n\n /**\n * Deletes a key from the map and emits the deleted entry to listeners.\n * Only emits if the key was actually deleted (existed in map).\n *\n * @see {@link Stream} - Complete copy-paste transformers library\n *\n * @example\n * ```typescript\n * const users = new Map([['alice', { age: 30 }], ['bob', { age: 25 }]]);\n * users.delete.listen(([key, value]) => console.log(`Removed: ${key}`));\n *\n * users.delete('alice'); // Removed: alice\n * users.delete('charlie'); // No emission (didn't exist)\n * ```\n */\n declare delete: ((key: KEY) => boolean) & Stream<[KEY, VALUE]>;\n\n /**\n * Clears all entries from the map and emits to listeners.\n * Only emits if the map was not already empty.\n *\n * @see {@link Stream} - Complete copy-paste transformers library\n *\n * @example\n * ```typescript\n * const store = new Map([['a', 1], ['b', 2]]);\n * store.clear.listen(() => console.log('Store cleared'));\n *\n * store.clear(); // Store cleared\n * store.clear(); // No emission (already empty)\n * ```\n */\n declare clear: (() => void) & Stream<void>;\n\n /**\n * Creates a new reactive Map.\n *\n * @param entries - Optional iterable of initial key-value pairs\n *\n * @see {@link Stream} - Complete copy-paste transformers library\n *\n * @example\n * ```typescript\n * // Empty map\n * const cache = new Map<string, any>();\n *\n * // With initial entries\n * const config = new Map([\n * ['theme', 'dark'],\n * ['lang', 'en']\n * ]);\n *\n * // Listen to changes\n * config.set.listen(([key, value]) => saveConfig(key, value));\n * config.delete.listen(([key]) => removeConfig(key));\n * ```\n */\n constructor(entries?: Iterable<[KEY, VALUE]>) {\n super(entries);\n\n const self = this;\n\n this.set = new Proxy(\n (key: KEY, value: VALUE): this => {\n if (globalThis.Map.prototype.has.call(self, key) && globalThis.Map.prototype.get.call(self, key) === value)\n return self;\n globalThis.Map.prototype.set.call(self, key, value);\n self._setStream?.push([key, value]);\n return self;\n },\n {\n get(target, prop) {\n if (prop in target) return (target as any)[prop];\n if (!self._setStream) self._setStream = new Stream();\n return (self._setStream as any)[prop];\n },\n }\n ) as any;\n\n this.delete = new Proxy(\n (key: KEY): boolean => {\n if (!globalThis.Map.prototype.has.call(self, key)) return false;\n const value = globalThis.Map.prototype.get.call(self, key);\n globalThis.Map.prototype.delete.call(self, key);\n self._deleteStream?.push([key, value]);\n return true;\n },\n {\n get(target, prop) {\n if (prop in target) return (target as any)[prop];\n if (!self._deleteStream) self._deleteStream = new Stream();\n return (self._deleteStream as any)[prop];\n },\n }\n ) as any;\n\n this.clear = new Proxy(\n (): void => {\n if (self.size > 0) {\n globalThis.Map.prototype.clear.call(self);\n self._clearStream?.push();\n }\n },\n {\n get(target, prop) {\n if (prop in target) return (target as any)[prop];\n if (!self._clearStream) self._clearStream = new Stream();\n return (self._clearStream as any)[prop];\n },\n }\n ) as any;\n }\n}\n",
12
+ "import { Stream } from \"../stream.ts\";\n\n/**\n * A reactive Set that extends the native Set with stream-based mutation events.\n * Emits events when items are added, deleted, or the set is cleared.\n *\n * @template VALUE - The type of values stored in the set\n *\n * @see {@link Stream} - Complete copy-paste transformers library\n *\n * @example\n * ```typescript\n * const activeUsers = new Set<string>();\n *\n * // Listen to additions\n * activeUsers.add.listen(userId => {\n * console.log(`User ${userId} came online`);\n * });\n *\n * // Listen to deletions\n * activeUsers.delete.listen(userId => {\n * console.log(`User ${userId} went offline`);\n * });\n *\n * activeUsers.add('alice'); // User alice came online\n * activeUsers.delete('alice'); // User alice went offline\n * ```\n */\nexport class Set<VALUE> extends globalThis.Set<VALUE> {\n protected _addStream?: Stream<VALUE>;\n protected _deleteStream?: Stream<VALUE>;\n protected _clearStream?: Stream<void>;\n\n /**\n * Adds a value to the set and emits the value to listeners.\n * Only emits if the value is actually added (not a duplicate).\n *\n * @see {@link Stream} - Complete copy-paste transformers library\n *\n * @example\n * ```typescript\n * const tags = new Set<string>();\n * tags.add.listen(tag => console.log('Added:', tag));\n *\n * tags.add('javascript'); // Added: javascript\n * tags.add('javascript'); // No emission (duplicate)\n * ```\n */\n declare add: ((value: VALUE) => this) & Stream<VALUE>;\n\n /**\n * Deletes a value from the set and emits the value to listeners.\n * Only emits if the value was actually deleted (existed in set).\n *\n * @see {@link Stream} - Complete copy-paste transformers library\n *\n * @example\n * ```typescript\n * const items = new Set(['a', 'b', 'c']);\n * items.delete.listen(item => console.log('Removed:', item));\n *\n * items.delete('b'); // Removed: b\n * items.delete('x'); // No emission (didn't exist)\n * ```\n */\n declare delete: ((value: VALUE) => boolean) & Stream<VALUE>;\n\n /**\n * Clears all values from the set and emits to listeners.\n * Only emits if the set was not already empty.\n *\n * @see {@link Stream} - Complete copy-paste transformers library\n *\n * @example\n * ```typescript\n * const cache = new Set([1, 2, 3]);\n * cache.clear.listen(() => console.log('Cache cleared'));\n *\n * cache.clear(); // Cache cleared\n * cache.clear(); // No emission (already empty)\n * ```\n */\n declare clear: (() => void) & Stream<void>;\n\n /**\n * Creates a new reactive Set.\n *\n * @param values - Optional iterable of initial values\n *\n * @see {@link Stream} - Complete copy-paste transformers library\n *\n * @example\n * ```typescript\n * // Empty set\n * const tags = new Set<string>();\n *\n * // With initial values\n * const colors = new Set(['red', 'green', 'blue']);\n *\n * // Listen to changes\n * colors.add.listen(color => updateUI(color));\n * colors.delete.listen(color => removeFromUI(color));\n * ```\n */\n constructor(values?: Iterable<VALUE>) {\n super(values);\n\n const self = this;\n\n this.add = new Proxy(\n (value: VALUE): this => {\n if (globalThis.Set.prototype.has.call(self, value)) return self;\n globalThis.Set.prototype.add.call(self, value);\n self._addStream?.push(value);\n return self;\n },\n {\n get(target, prop) {\n if (prop in target) return (target as any)[prop];\n if (!self._addStream) self._addStream = new Stream<VALUE>();\n return (self._addStream as any)[prop];\n },\n }\n ) as any;\n\n this.delete = new Proxy(\n (value: VALUE): boolean => {\n if (!globalThis.Set.prototype.has.call(self, value)) return false;\n globalThis.Set.prototype.delete.call(self, value);\n self._deleteStream?.push(value);\n return true;\n },\n {\n get(target, prop) {\n if (prop in target) return (target as any)[prop];\n if (!self._deleteStream) self._deleteStream = new Stream<VALUE>();\n return (self._deleteStream as any)[prop];\n },\n }\n ) as any;\n\n this.clear = new Proxy(\n (): void => {\n if (self.size > 0) {\n globalThis.Set.prototype.clear.call(self);\n self._clearStream?.push();\n }\n },\n {\n get(target, prop) {\n if (prop in target) return (target as any)[prop];\n if (!self._clearStream) self._clearStream = new Stream<void>();\n return (self._clearStream as any)[prop];\n },\n }\n ) as any;\n }\n}\n",
13
+ "import { FunctionGenerator, Stream } from \"../stream.ts\";\n\n/**\n * A reactive state container that extends Stream to provide stateful value management.\n *\n * @template VALUE - The type of the state value\n *\n * @see {@link Stream} - Complete copy-paste transformers library\n *\n * @example\n * ```typescript\n * // Basic state\n * const counter = new State(0);\n * counter.listen(value => console.log('Counter:', value));\n * counter.value = 5; // Counter: 5\n *\n * // State from stream\n * const source = new Stream<number>();\n * const state = new State(0, source);\n * state.listen(value => console.log('State:', value));\n * source.push(1, 2, 3); // State: 1, State: 2, State: 3\n *\n * // State from transformed stream\n * const filtered = source.pipe(filter({}, (_, v) => [v > 0, {}]));\n * const derivedState = new State(-1, filtered);\n * ```\n */\nexport class State<VALUE> extends Stream<VALUE> {\n protected _value: VALUE;\n constructor(initialValue: VALUE);\n constructor(initialValue: VALUE, stream: FunctionGenerator<VALUE> | Stream<VALUE>);\n /**\n * Creates a new State with an initial value.\n *\n * @param initialValue - The initial state value\n *\n * @see {@link Stream} - Complete copy-paste transformers library\n *\n * @example\n * ```typescript\n * const count = new State(0);\n * const theme = new State<'light' | 'dark'>('light');\n * const user = new State<User | null>(null);\n * ```\n */\n constructor(initialValue: VALUE, stream?: FunctionGenerator<VALUE> | Stream<VALUE>) {\n stream ? super(stream) : super();\n this._value = initialValue;\n }\n /**\n * Updates the state with one or more values sequentially.\n * Each value triggers listeners and updates the current state.\n *\n * @param values - Values to set as state\n *\n * @see {@link Stream} - Complete copy-paste transformers library\n *\n * @example\n * ```typescript\n * const state = new State(0);\n * state.listen(v => console.log(v));\n *\n * state.push(1, 2, 3); // Logs: 1, 2, 3\n * console.log(state.value); // 3\n * ```\n */\n override push(...values: VALUE[]): void {\n for (const value of values) {\n this.value = value;\n }\n }\n /**\n * Gets the current state value.\n *\n * @see {@link Stream} - Complete copy-paste transformers library\n *\n * @example\n * ```typescript\n * const state = new State('hello');\n * console.log(state.value); // 'hello'\n * ```\n */\n get value(): VALUE {\n return this._value;\n }\n /**\n * Sets the current state value and notifies all listeners.\n *\n * @param value - The new state value\n *\n * @see {@link Stream} - Complete copy-paste transformers library\n *\n * @example\n * ```typescript\n * const state = new State(0);\n * state.listen(v => console.log('New value:', v));\n *\n * state.value = 42; // New value: 42\n * state.value = 100; // New value: 100\n * ```\n */\n set value(value: VALUE) {\n this._value = value;\n super.push(value);\n }\n}\n"
14
14
  ],
15
- "mappings": "AA8BO,MAAM,CAAwD,CACzD,WAA0C,IAAI,IAC9C,aACA,WACA,eACA,iBAoCV,WAAW,CAAC,EAAiD,CAC3D,KAAK,aAAe,KAkBlB,aAAY,EAAY,CAC1B,OAAO,KAAK,WAAW,KAAO,KAc5B,cAAa,EAAiB,CAChC,IAAK,KAAK,eAAgB,KAAK,eAAiB,IAAI,EACpD,OAAO,KAAK,kBAeV,gBAAe,EAAiB,CAClC,IAAK,KAAK,iBAAkB,KAAK,iBAAmB,IAAI,EACxD,OAAO,KAAK,wBAEN,OAAO,cAAc,EAAgC,CAC3D,IAAM,EAAiB,CAAC,EACpB,EAEE,EAAQ,KAAK,OAAO,CAAC,IAAU,CACnC,EAAM,KAAK,CAAK,EAChB,IAAW,EACZ,EAED,GAAI,CACF,MAAO,GACL,GAAI,EAAM,OAAQ,MAAM,EAAM,MAAM,EAC/B,WAAM,IAAI,QAA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