std/stream

Streams: one flow in one direction, with a reading end and a writing end.

"Stream" is the word for the flow, not a type. What a signature names is one of its two ends - Source<Item, Failure> to read from, Sink<Item, Failure> to write into - and they are the asynchronous siblings of Iterator and Accumulator, with the same verbs (next, add, finish). Everything in between, every map, filter and framer, is a Stage of std/iteration and is written once for both worlds.

const all = response.body.through(Json.items<User>()).checked().toList().await()?
File.write(path, response.body.mapFailure(IoError.from)).await()?

A wire protocol that reads a byte stream item by item - a run of bytes, a line, a frame behind its length - reads it through a Reader, which keeps what arrived and was not read yet.

See docs/design/STREAMS.md for the whole model: the contracts of both ends, what is synchronous and what has to wait, the drivers, and what was taken from Rust, C#, Swift, Scala, Java, Node, Web Streams and Bun.

Modules

Everything