system.collection

Higher-order functions for working with arrays and collections.

Import

import system.collection as c;

Transformation Functions

map(arr, fn) → array

Apply a function to each element, returning a new array.

c.map([1, 2, 3], (x) => x * 2)  // [2, 4, 6]

filter(arr, fn) → array

Return elements that satisfy the predicate.

c.filter([1, 2, 3, 4], (x) => x % 2 == 0)  // [2, 4]

reduce(arr, fn, initial) → value

Reduce array to a single value.

c.reduce([1, 2, 3], (acc, x) => acc + x, 0)  // 6

Query Functions

find(arr, fn) → value

Find first element matching predicate.

any(arr, fn) → bool

Check if any element matches.

all(arr, fn) → bool

Check if all elements match.

count(arr, fn) → int

Count matching elements.

Array Operations

length(arr) → int

Return array length.

push(arr, val) → array

Add element to end.

pop(arr) → value

Remove and return last element.

slice(arr, start, end) → array

Extract subarray.

reverse(arr) → array

Return reversed array.

sort(arr) → array

Return sorted array.