Repository navigation
Item Streams
std::stream provides single-consumer streams outside pipeline syntax. A Reader
advances through next_item, can expose a final result or context, and can be
closed explicitly.
import std::stream
let $source = std::stream::from_iterable [2, 4, 7]
let $scaled = std::stream::map $source fn ($n: Integer): Integer { $n * 5 }
let $selected = std::stream::filter $scaled fn ($n: Integer): Boolean { $n >= 20 }
let $items = std::stream::collect $selected
echo $items...
20 35
map and filter defer work until a consumer asks for items. collect deliberately
materializes the remaining items. Re-reading a consumed stream does not restart it.
Closing an adapter releases its owned operation and upstream resources according
to that adapter's ownership contract.
A custom iterator returns actual () to signal completion. When a stream needs
to carry a unit item, use its boxed representation: Item(value: ()). A boxed
Reader distinguishes this from the end of the stream. Native arrays retain unit
items when adapted through from_iterable.
A Reader can be created with callbacks for the next item, final result, closing, and context. Keep callbacks small and explicit about errors. Resources and errors remain subject to the same ownership and propagation rules as other code.
Use language pipelines for concise stage syntax. Use explicit streams when a library needs to return a lazy sequence, preserve final metadata, or control its consumption and closing policy. JSON and network adapters use these same Readers.
Related: Iteration protocol · Pipelines · JSON
Begin here
Values and expressions
- Language basics
- Variables and scope
- Numbers and logic
- Strings and paths
- Arrays
- Hash maps
- Ranges and iteration
- Control flow
- Match and type guards
Functions and types
- Functions and calls
- Closures and function types
- Methods and properties
- Structs
- Enums
- Named types and unions
- Conversions
- Types and properties
Shell and modules
- Pipelines
- Pipeline splits
- Pipeline formats
- Commands and exit status
- Redirection
- Environment and exported variables
- Modules and visibility
- Nested modules and directory packages
- Conditional imports and declarations
- Errors and cleanup
- Supervised processes and terminals
Library guides
- Standard library
- The implicit prelude
- Bytes, files, readers, and writers
- Explicit item streams
- JSON documents and typed mapping
- Sockets, DNS, and TLS
- HTTP clients
- HTTP servers
- Framing, server-sent events, and JSON-RPC
- Terminal colors, styles, and geometry
- Build an application console
Interactive use