Built-in routines

Reductions — sum, min, max & [OP]

Full

Collapse a list to a single value with sum/min/max or the reduction metaoperator.

Reducing folds a list down to one value. Common reductions have named routines (sum, min, max), and any infix operator can reduce via the [ ] metaoperator.

The reduction metaoperator [OP] #

[+] inserts + between all the elements — [+] 1..5 is 1 + 2 + 3 + 4 + 5. Any associative infix works: [*] multiplies.

say [+] 1..5;
say [*] 1..5;
Output
15
120

Named reductions #

sum, min, and max are the common ones as methods (or subs).

say (3, 7, 2, 9).max;
say (3, 7, 2, 9).min;
say (1..5).sum;
Output
9
2
15

Notes #