Reduce
Stream reduction: fold, toList, length, sum, signal, signalOn, any, all.
all
all: return true if every element satisfies the predicate; short-circuits on first miss via lazy evaluation of the stream tail.
all : (a -> Bool) -> Computation (Step r a) -> Computation Bool
Check if all elements satisfy a predicate. Short-circuits on first failing element.
any
any: return true if any element satisfies the predicate; short-circuits on first match via lazy evaluation of the stream tail.
any : (a -> Bool) -> Computation (Step r a) -> Computation Bool
Check if any element satisfies a predicate. Short-circuits on first match — the rest of the stream is never forced.
fold
fold: left-fold a stream into a single value with initial accumulator z; the canonical terminal combinator other reducers delegate to.
fold : (b -> a -> b) -> b -> Computation (Step r a) -> Computation b
Left fold over a stream. Drains the stream, threading the
accumulator through f for each element.
length
length: count the number of elements in a stream; equivalent to fold (n: _: n + 1) 0 over the stream's element steps.
length : Computation (Step r a) -> Computation Int
Count the number of elements in a stream.
signal
signal: emit z then forward only values not structurally equal to the previous emission; specialisation of signalOn over ==.
signal : a -> Computation (Step r a) -> Computation (Step r a)
Return a stream that emits only when the incoming values change,
using structural equality to detect duplicates.
Equivalent to signalOn z (x: y: x == y).
signalOn
signalOn: emit z then forward only values the comparator deems different from the previous emission; suppresses runs of equivalent inputs.
signalOn : a -> (a -> a -> Bool) -> Computation (Step r a) -> Computation (Step r a)
Return a stream that emits only when the incoming values change. The comparator receives the current value and the next stream value; if they compare equal, the next value is skipped.
The returned stream begins with the provided initial value z.
sum
sum: sum all numeric elements in a stream starting from 0; equivalent to fold (acc: x: acc + x) 0.
sum : Computation (Step r Number) -> Computation Number
Sum all numeric elements in a stream. Initial accumulator is 0.
toList
toList: collect all stream elements into a list in emission order; equivalent to fold (acc: x: acc ++ [x]) [].
toList : Computation (Step r a) -> Computation [a]
Collect all stream elements into a list, preserving emission order.