@soffinal/stream 0.1.3 → 0.1.4
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 +49 -13
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -29,6 +29,7 @@ A modern, async-first streaming library that treats asynchronous data flow as a
|
|
|
29
29
|
- 🔄 **Multicast by Default** - One stream, many consumers
|
|
30
30
|
- ⏳ **Awaitable Streams** - `await stream` for next value
|
|
31
31
|
- 🔁 **Async Iterable** - Use `for await` loops naturally
|
|
32
|
+
- ⚡ **Async Operations** - All transformers support async functions while maintaining order
|
|
32
33
|
- 🧠 **Smart Caching** - Operations run once, results shared
|
|
33
34
|
- 🗑️ **Auto Cleanup** - Memory management handled automatically
|
|
34
35
|
- 🔧 **Dual Programming Paradigms** - Method chaining or functional pipe composition
|
|
@@ -130,6 +131,17 @@ const result = stream
|
|
|
130
131
|
.map((x) => x * 2)
|
|
131
132
|
.group((batch) => batch.length >= 5);
|
|
132
133
|
|
|
134
|
+
// Async operations with order preservation
|
|
135
|
+
const asyncProcessed = stream
|
|
136
|
+
.filter(async (value) => {
|
|
137
|
+
const isValid = await validateAsync(value);
|
|
138
|
+
return isValid;
|
|
139
|
+
})
|
|
140
|
+
.map(async (value) => {
|
|
141
|
+
const enriched = await enrichWithExternalData(value);
|
|
142
|
+
return { original: value, enriched };
|
|
143
|
+
});
|
|
144
|
+
|
|
133
145
|
// Stateful operations with initial state
|
|
134
146
|
const stateful = stream
|
|
135
147
|
.filter(0, (prev, curr) => [curr > prev, Math.max(prev, curr)]) // Only increasing values
|
|
@@ -152,6 +164,12 @@ const result = stream
|
|
|
152
164
|
.pipe(map((x) => x * 2))
|
|
153
165
|
.pipe(group((batch) => batch.length >= 5));
|
|
154
166
|
|
|
167
|
+
// Async functional transformers (order preserved)
|
|
168
|
+
const asyncPipeline = stream
|
|
169
|
+
.pipe(filter(async (x) => await isValidAsync(x)))
|
|
170
|
+
.pipe(map(async (x) => await processAsync(x)))
|
|
171
|
+
.pipe(group(batch => batch.length >= 5));
|
|
172
|
+
|
|
155
173
|
// Stateful functional transformers
|
|
156
174
|
const advanced = stream
|
|
157
175
|
.pipe(filter(0, (prev, curr) => [curr > prev, Math.max(prev, curr)]))
|
|
@@ -266,13 +284,17 @@ activeUsers.add.listen((userId) => showOnlineStatus(userId));
|
|
|
266
284
|
#### Methods
|
|
267
285
|
|
|
268
286
|
- `push(...values: T[]): void` - Emit values to all listeners
|
|
269
|
-
- `listen(callback: (value: T) => void, signal?: AbortSignal): () => void` - Add listener
|
|
270
|
-
- `filter(predicate: (value: T) =>
|
|
271
|
-
- `
|
|
272
|
-
- `
|
|
273
|
-
- `
|
|
274
|
-
- `
|
|
275
|
-
- `
|
|
287
|
+
- `listen(callback: (value: T) => void, signal?: AbortSignal): () => void` - Add listener, returns cleanup function
|
|
288
|
+
- `filter<U extends T>(predicate: (value: T) => value is U): Stream<U>` - Filter with type guard
|
|
289
|
+
- `filter(predicate: (value: T) => boolean | Promise<boolean>): Stream<T>` - Filter with async predicate
|
|
290
|
+
- `filter<S>(initialState: S, accumulator: (state: S, value: T) => [boolean, S] | Promise<[boolean, S]>): Stream<T>` - Stateful filtering
|
|
291
|
+
- `map<U>(mapper: (value: T) => U | Promise<U>): Stream<U>` - Transform with async mapper
|
|
292
|
+
- `map<S, U>(initialState: S, accumulator: (state: S, value: T) => [U, S] | Promise<[U, S]>): Stream<U>` - Stateful mapping
|
|
293
|
+
- `group(predicate: (batch: T[]) => boolean | Promise<boolean>): Stream<T[]>` - Group into batches
|
|
294
|
+
- `group<S>(initialState: S, accumulator: (state: S, value: T) => [boolean, S] | Promise<[boolean, S]>): Stream<S>` - Stateful grouping
|
|
295
|
+
- `merge<STREAMS extends [Stream<any>, ...Stream<any>[]]>(...streams: STREAMS): Stream<T | ValueOf<STREAMS[number]>>` - Merge multiple streams
|
|
296
|
+
- `flat<DEPTH extends number = 0>(depth?: DEPTH): Stream<FlatArray<T, DEPTH>>` - Flatten arrays with configurable depth
|
|
297
|
+
- `pipe<U>(transformer: (stream: Stream<T>) => Stream<U>): Stream<U>` - Apply functional transformer
|
|
276
298
|
|
|
277
299
|
#### Async Interface
|
|
278
300
|
|
|
@@ -287,13 +309,27 @@ activeUsers.add.listen((userId) => showOnlineStatus(userId));
|
|
|
287
309
|
|
|
288
310
|
### Transformer Functions
|
|
289
311
|
|
|
290
|
-
Functional transformers for use with `pipe()
|
|
312
|
+
Functional transformers for use with `pipe()` - all support async operations:
|
|
313
|
+
|
|
314
|
+
#### filter
|
|
315
|
+
- `filter<T, U extends T>(predicate: (value: T) => value is U): (stream: Stream<T>) => Stream<U>`
|
|
316
|
+
- `filter<T>(predicate: (value: T) => boolean | Promise<boolean>): (stream: Stream<T>) => Stream<T>`
|
|
317
|
+
- `filter<T, S>(initialState: S, accumulator: (state: S, value: T) => [boolean, S] | Promise<[boolean, S]>): (stream: Stream<T>) => Stream<T>`
|
|
318
|
+
|
|
319
|
+
#### map
|
|
320
|
+
- `map<T, U>(mapper: (value: T) => U | Promise<U>): (stream: Stream<T>) => Stream<U>`
|
|
321
|
+
- `map<T, S, U>(initialState: S, accumulator: (state: S, value: T) => [U, S] | Promise<[U, S]>): (stream: Stream<T>) => Stream<U>`
|
|
322
|
+
|
|
323
|
+
#### group
|
|
324
|
+
- `group<T>(predicate: (batch: T[]) => boolean | Promise<boolean>): (stream: Stream<T>) => Stream<T[]>`
|
|
325
|
+
- `group<T, S>(initialState: S, accumulator: (state: S, value: T) => [boolean, S] | Promise<[boolean, S]>): (stream: Stream<T>) => Stream<S>`
|
|
326
|
+
|
|
327
|
+
#### merge
|
|
328
|
+
- `merge<STREAMS extends [Stream<any>, ...Stream<any>[]]>(...streams: STREAMS): <T>(stream: Stream<T>) => Stream<T | ValueOf<STREAMS[number]>>`
|
|
291
329
|
|
|
292
|
-
|
|
293
|
-
- `
|
|
294
|
-
- `
|
|
295
|
-
- `merge<T>(...streams: Stream<T>[]): (stream: Stream<T>) => Stream<T>`
|
|
296
|
-
- `flat<T>(depth?: number): (stream: Stream<T>) => Stream<U>`
|
|
330
|
+
#### flat
|
|
331
|
+
- `flat(): <T>(stream: Stream<T>) => Stream<FlatArray<T, 0>>`
|
|
332
|
+
- `flat<DEPTH extends number>(depth: DEPTH): <T>(stream: Stream<T>) => Stream<FlatArray<T, DEPTH>>`
|
|
297
333
|
|
|
298
334
|
### Reactive Collections
|
|
299
335
|
|