system.collection
The system.collection module provides higher-order functions for working with arrays and collections.
Import
import system.collection as c;
Functions
Transformation
map(arr, fn)- Transform each elementfilter(arr, fn)- Keep elements matching predicatereduce(arr, fn, initial)- Reduce to single value
Queries
find(arr, fn)- Find first matching elementany(arr, fn)- Check if any matchall(arr, fn)- Check if all matchcount(arr, fn)- Count matching elements
Array Operations
length(arr)- Array lengthpush(arr, val)- Add elementpop(arr)- Remove last elementslice(arr, start, end)- Extract subarrayreverse(arr)- Reverse arraysort(arr)- Sort array
Example
import system.collection as c;
import system.io as io;
let nums = [1, 2, 3, 4, 5];
// Map: double each number
let doubled = c.map(nums, (x) => x * 2);
io.out.println(doubled); // [2, 4, 6, 8, 10]
// Filter: keep even numbers
let evens = c.filter(nums, (x) => x % 2 == 0);
io.out.println(evens); // [2, 4]
// Reduce: sum all numbers
let sum = c.reduce(nums, (acc, x) => acc + x, 0);
io.out.println("Sum:", sum); // 15