Matching streams
Take one apart with when, and build one lazily.
main (streams, print)
# when takes a stream apart: empty, or a head followed by a tail.
# Building a stream from a recursive call keeps it lazy.
runningTotal(s |int|, acc int) |int|
when s is
|int:| |int:|
|int: head, *tail| |int: acc + head, *runningTotal(tail, acc + head)|
main()
sums = streams.collect(runningTotal(streams.range(1, 6), 0), [int:])
print.line("{sums[0]} {sums[4]}")1 15