Stream<A, E, R> represents a description of a program that may emit zero or more values of type A, may fail with errors of type E, and uses a context of type R.
Streams are pull-based, offering inherent laziness and backpressure. They form a monad on the A type parameter and provide error management facilities similar to Effect.
Type Parameters
A: The type of values emitted by the streamE: The type of errors the stream can fail with (defaults tonever)R: The context type required by the stream (defaults tonever)
Creating Streams
From Values
From Effects
Async Streams
Resource Management
Transforming Streams
Mapping
Filtering
Taking and Dropping
FlatMapping
Combining Streams
Concatenation
Merging
Zipping
Cross Product
Stream Consumption
Running Streams
Using Sinks
Buffering and Timing
Buffering
Debouncing and Throttling
Scheduling
Broadcasting
Error Handling
Grouping and Windowing
Common Patterns
Streaming Pipeline
Infinite Streams
Pagination
Interruption
Performance Tips
- Chunking: Streams emit chunks of values for efficiency. Use
rechunkto optimize chunk size. - Buffering: Use
bufferorbufferChunksto decouple fast producers from slow consumers. - Concurrency: Use
flatMapwithconcurrencyoption for parallel processing. - Resource Management: Always use
acquireReleaseorensuringfor proper cleanup.
See Also
- Sink - Stream consumers
- Channel - Low-level streaming primitive
- SubscriptionRef - Reactive state management