Creating Streams
Streams can be created from various data sources.From Iterables
The simplest way to create a stream is from an array or any iterable:From Effects with Schedules
Create polling streams that emit values on a schedule:From Paginated APIs
UseStream.paginate for APIs that return data one page at a time:
From Async Iterables
Convert async iterables into streams:From Event Listeners
Create streams from DOM events:From Callbacks
For any callback-based API, useStream.callback:
From Node.js Streams
Convert Node.js readable streams:Transforming Streams
Streams provide rich operators for transformation.Pure Transformations
UseStream.map for pure per-element transforms:
Filtering
Exclude elements that don’t match a predicate:FlatMap
Transform each element into a stream and flatten the results:Effectful Transformations
UseStream.mapEffect for transformations that require effects:
Consuming Streams
Streams are consumed using variousrun* methods.
Collecting All Elements
Gather all stream outputs into an array:Running for Effects
Run the stream for its effects, ignoring outputs:Processing Each Element
Execute an effectful consumer for every element:Folding/Reducing
Reduce the stream to one accumulated value:Using Sinks
Consume streams through sinks:Getting First/Last Elements
Capture edge elements as Option values:Windowing and Limiting
Control how much of a stream is processed.Taking Elements
Dropping Elements
Conditional Taking
Encoding and Decoding Streams
Use channels to decode and encode streams of structured data.Stream Patterns
- Merging Streams
- Zipping Streams
- Buffering
- Grouping
Error Handling in Streams
Streams propagate errors through the error channel:Best Practices
Use Streams for Sequences
Prefer streams over arrays when working with large datasets, infinite sequences, or data that arrives over time.
Control Concurrency
Always specify concurrency limits with
mapEffect and flatMap to prevent resource exhaustion.Compose Operators
Build complex stream pipelines by composing simple operators. Keep individual transformations focused.
Handle Errors
Use
Stream.catchAll, Stream.orElse, or Stream.retry to handle errors gracefully in stream pipelines.Next Steps
Concurrency
Learn about concurrent operations and fiber management
Error Handling
Handle errors in streams and effects
