@reduce
Reduce an array to a single value by applying a helper.
Returns: any
Syntax
Section titled “Syntax”@reduce(arr fn initial)Arguments
Section titled “Arguments”| Name | Type | Description |
|---|---|---|
arr |
array |
Source array |
fn |
helper |
Reducer helper receiving (accumulator, element) |
initial |
any |
Initial accumulator value |
Examples
Section titled “Examples”# Sum an arraydef @add "$acc: number $n: number -> number" @num($acc + $n)set $nums [1 2 3 4]set $sum @reduce($nums @add 0)