Stream

An effectful iterator: identical to Iter except that its step! thunk is effectful, so combinators like [Stream.map!] can run effects per element while staying lazy. Produced from an Iter via [Iter.map!] and driven by [Stream.collect!].

from_iter : Iter(item) -> Stream(item)

Lift a pure Iter into a Stream. The lifted steps do no effect themselves, but the stream can then be combined with effectful operations like Stream.map. Carries the source's length forward so [Stream.collect!] can pre-size.

map : Stream(a), (a => b) -> Stream(b)

Transform each item of this stream. The transform may run effects; because the stream's steps are already effectful, building the mapped stream stays lazy (the transform runs only as the stream is driven).

map! : Stream(a), (a => b) => Stream(b)

Transform each item of this stream with an effectful function.

next! : Stream(item) => [One({ item : item, rest : Stream(item) }), Skip({ rest : Stream(item) }), Done]

Advance the stream by one step.

size_hint : Stream(item) -> [Known(U64), Unknown]

Returns the stream's length if it is known up front.

collect! : Stream(item) => List(item)

Drive the stream to completion with an explicit loop, collecting its items into a List (pre-sized from len_if_known when known).