# 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.

