Map, Filter, Reduce
Higher-order array operations that take a function and apply it across elements. Map transforms, filter selects, and reduce accumulates. All three work with closures, named functions, and UFCS chaining.
|
|
|
|
|
|
All three work with UFCS, so you can chain them naturally. This reads top to bottom: keep evens, triple them, sum the results. |
|
Closures capture variables from the surrounding scope. |
|
Works on strings too. |
|
$ pyr run map-filter-reduce.pyr [2, 4, 6, 8, 10] [10, 20, 30, 40, 50] [3, 4, 5] 15 36 [4, 5] ["HELLO", "WORLD"] |