Collection — Collection Operations
Part of the std module. Available via import std.
Collection operations for arrays, sets, and optionals.
Interface
for
interface for: f a. (a. b). f b
Map a function over a collection. Built-in support exists for arrays, sets, and optionals without importing std.
for [1, 2, 3] (x. x + 1) | [2, 3, 4]
for names (name. "Hi, " ++ name)
for is map with the arguments flipped: the collection comes first, then the function.
Functions
reduce
reduce: xs:[a]. f:(a. b. b). b:b. b
Fold over a structure, accumulating a result. Built-in support for arrays, sets, and optionals.
reduce [1, 2, 3] (x. acc. x + acc) 0
iterate
iterate: xs:[a]. f:(a. [b]). [b]
Monadic bind for arrays. Applies a function that returns an array to each element and flattens the results.
zip
zip: xs:[a]. ys:[b]. [Tuple a b]
Combine two arrays into an array of pairs. Uses the Tuple type from algebra.dox (also in std).