datastream/sink
Side-effecting terminal consumers over Stream(a).
sink is the effectful half of the terminal layer; pure reductions
live in fold. The split is intentional: a reader can tell from
the import whether a function is pure (fold) or effectful (sink).
fold.drain already covers the “evaluate and discard” case, so a
sink.drain synonym is intentionally omitted.
Values
pub fn each(
over stream: datastream.Stream(a),
with effect: fn(a) -> Nil,
) -> Nil
Drive the stream to completion, calling effect once per element
in source order. Returns Nil.
Use this when the work the consumer does is infallible. For
fallible consumers use try_each.
pub fn println(stream: datastream.Stream(String)) -> Nil
Print every element of stream followed by a newline to standard
output, in source order.
Cross-target convenience over gleam/io.println. Target-aware
sinks (file, socket, …) belong outside the cross-target core.
pub fn try_each(
over stream: datastream.Stream(a),
with effect: fn(a) -> Result(Nil, e),
) -> Result(Nil, e)
Drive the stream while effect returns Ok(Nil), halting on the
first Error(e) and returning that error.
On all-Ok returns Ok(Nil). On the first Error(e), no further
element is pulled from upstream and the upstream’s close callback
is invoked before Error(e) is returned, so resource-backed
sources are released even on the early-exit path.