Language Methods
Built-in collection and text types with their methods.
Ordered collection of values. Construct with #[1, 2, 3] or Array(1, 2, 3).
Constructor
Section titled “Constructor”fn Array(...items) -> ArrayCreates an array from individual values. Prefer the #[1, 2, 3] literal syntax. This constructor is kept for compatibility.
Example:
Array(1, 2, 3) returns #[1, 2, 3]
Parameters:
items(Array) — variadic values to collect into the array
Returns: Array — a new array of the given values
length
Section titled “length”fn length() -> NumberReturns the number of elements.
Returns: Number — the element count
fn push(value: any) -> ArrayAdds an element to the end of the array.
Parameters:
value(Any) — the element to add
Returns: Array — the array, for chaining
fn popFunctionRemoves and returns the last element. Errors on empty array.
Returns: Any — the removed last element
fn get(index: Number)Returns the element at the given index. Errors if the index is out of bounds.
Parameters:
index(Number) — zero-based position
Returns: Any — the element at index
fn slice(start: Number, end: Number) -> ArrayReturns a subarray from start (inclusive) to end (exclusive).
Parameters:
start(Number) — start index (inclusive, 0-based)end(Number) — end index (exclusive)
Returns: Array — the subarray
concat
Section titled “concat”fn concat(other: Array) -> ArrayReturns a new array with elements from both arrays.
Parameters:
other(Array) — array to append
Returns: Array — a new array with the elements of both
reverse
Section titled “reverse”fn reverse() -> ArrayReturns a new array with elements in reverse order.
Returns: Array — a new reversed array
contains
Section titled “contains”fn contains(value: any) -> BooleanReturns true if the array contains the given value.
Parameters:
value(Any) — the value to search for
Returns: Boolean — true if the value is present
fn map(func: Function) -> ArrayApplies a function to each element, returns a new array.
Parameters:
func(Function) — fn(element) -> new_element
Returns: Array — a new array of transformed elements
filter
Section titled “filter”fn filter(func: Function) -> ArrayReturns a new array with only elements satisfying the predicate.
Parameters:
func(Function) — fn(element) -> bool
Returns: Array — a new array of matching elements
reduce
Section titled “reduce”fn reduce(func: Function, initial: any)Reduces the array to a single value.
Parameters:
func(Function) — fn(accumulator, element) -> new_accumulatorinitial(Any) — starting accumulator value
Returns: Any — the final accumulated value
fn iter() -> IteratorReturns an iterator over the array elements.
Returns: Iterator — an iterator over the elements
Key-value mapping with String or Number keys. Construct with #{"key": value} literal syntax.
fn get(key: String or Number)Returns the value for the given key, or NUL if not found.
Parameters:
key(String | Number) — the key to look up
Returns: Any — the value for key, or NUL if absent
fn set(key: String or Number, value: any) -> DictSets a key-value pair in place.
Parameters:
key(String | Number) — the key to setvalue(Any) — the value to associate
Returns: Dict — the dict, for chaining
remove
Section titled “remove”fn remove(key: String or Number)Removes a key in place.
Parameters:
key(String | Number) — the key to remove
Returns: Any — the removed value, or NUL if the key was not found
fn keys() -> ArrayReturns an Array of all keys.
Returns: Array — all keys
values
Section titled “values”fn values() -> ArrayReturns an Array of all values.
Returns: Array — all values
length
Section titled “length”fn length() -> NumberReturns the number of entries.
Returns: Number — the entry count
contains_key
Section titled “contains_key”fn contains_key(key: String or Number) -> BooleanReturns true if the dict contains the given key.
Parameters:
key(String | Number) — the key to check
Returns: Boolean — true if key is present
entries
Section titled “entries”fn entries() -> ArrayReturns an Array of [key, value] pairs.
Returns: Array — one [key, value] pair per entry
fn merge(other: Dict) -> DictReturns a new dict with entries from both dicts merged. Does not mutate either dict.
Parameters:
other(Dict) — dict to merge in (its keys override on conflict)
Returns: Dict — a new merged dict
fn map(func: Function) -> DictTransforms values using a function.
Parameters:
func(Function) — fn(key, value) -> new_value
Returns: Dict — a new dict with transformed values
filter
Section titled “filter”fn filter(func: Function) -> DictFilters entries by predicate.
Parameters:
func(Function) — fn(key, value) -> bool
Returns: Dict — a new dict with matching entries
reduce
Section titled “reduce”fn reduce(func: Function, initial: any)Reduces entries to a single value.
Parameters:
func(Function) — fn(accumulator, key, value) -> new_accumulatorinitial(Any) — starting accumulator value
Returns: Any — the final accumulated value
fn iter() -> IteratorReturns an Iterator over the keys.
Returns: Iterator — an iterator over the keys
Iterator
Section titled “Iterator”Lazy sequence of values with chainable transformations. Obtain from .iter() on arrays, strings, or patterns.
fn nextFunctionReturns the next value, or nil if exhausted.
Returns: Any — the next value, or nil if exhausted
fn take(n: Number) -> IteratorReturns a lazy iterator yielding the first n elements.
Parameters:
n(Number) — maximum number of elements to yield
Returns: Iterator — a lazy iterator over the first n elements
collect
Section titled “collect”fn collect() -> ArrayCollects all remaining elements into an array.
Returns: Array — the remaining elements
fn skip(n: Number) -> IteratorReturns a lazy iterator that skips the first n elements.
Parameters:
n(Number) — number of elements to skip
Returns: Iterator — a lazy iterator past the first n elements
fn count() -> NumberCounts remaining elements (consumes the iterator).
Returns: Number — the count of remaining elements
step_by
Section titled “step_by”fn step_by(step: Number) -> IteratorReturns a lazy iterator yielding every nth element.
Parameters:
step(Number) — take every nth element
Returns: Iterator — a lazy iterator over every step-th element
enumerate
Section titled “enumerate”fn enumerate() -> IteratorReturns a lazy iterator yielding [index, value] pairs.
Returns: Iterator — a lazy iterator of [index, value] pairs
fn firstFunctionReturns the first element, or nil if empty.
Returns: Any — the first element, or nil if empty
fn lastFunctionReturns the last element, or nil if empty. Warning: consumes the entire iterator; hangs on infinite iterators.
Returns: Any — the last element, or nil if empty
fn map(func: Function) -> ArrayApplies a function to each element, returns an array.
Parameters:
func(Function) — fn(element) -> new_element
Returns: Array — a new array of transformed elements
filter
Section titled “filter”fn filter(func: Function) -> ArrayFilters elements by predicate, returns an array.
Parameters:
func(Function) — fn(element) -> bool
Returns: Array — a new array of matching elements
fn find(func: Function)Returns the first element matching the predicate, or nil.
Parameters:
func(Function) — fn(element) -> bool
Returns: Any — the first matching element, or nil
fn any(func: Function) -> BooleanReturns true if any element matches the predicate.
Parameters:
func(Function) — fn(element) -> bool
Returns: Boolean — true if at least one element matches
fn all(func: Function) -> BooleanReturns true if all elements match the predicate.
Parameters:
func(Function) — fn(element) -> bool
Returns: Boolean — true if every element matches
fn fold(initial: any, func: Function)Folds the iterator to a single value.
Parameters:
initial(Any) — starting accumulator valuefunc(Function) — fn(accumulator, element) -> new_accumulator
Returns: Any — the final accumulated value
fn zip(other: Iterator) -> IteratorZips this iterator with another, yielding [a, b] pairs.
Parameters:
other(Iterator) — iterator to zip with
Returns: Iterator — a lazy iterator of [a, b] pairs
fn chain(other: Iterator) -> IteratorChains another iterator after this one.
Parameters:
other(Iterator) — iterator to append
Returns: Iterator — a lazy iterator over both in sequence
flatten
Section titled “flatten”fn flatten() -> ArrayFlattens nested arrays into a single array.
Returns: Array — the flattened elements
String
Section titled “String”Text value with Unicode support. Construct with literal syntax "hello".
length
Section titled “length”fn length() -> NumberReturns the character count (Unicode-aware).
Returns: Number — the character count
uppercase
Section titled “uppercase”fn uppercase() -> StringReturns the string converted to uppercase.
Returns: String — the uppercased string
lowercase
Section titled “lowercase”fn lowercase() -> StringReturns the string converted to lowercase.
Returns: String — the lowercased string
substring
Section titled “substring”fn substring(start: Number, end: Number) -> StringReturns a substring from start to end (Unicode-aware).
Parameters:
start(Number) — start index (inclusive, 0-based)end(Number) — end index (exclusive)
Returns: String — the substring
fn split(delimiter: String) -> ArraySplits the string by a delimiter, returns an array of strings.
Parameters:
delimiter(String) — the string to split on
Returns: Array — the parts as Strings
contains
Section titled “contains”fn contains(needle: String) -> BooleanReturns true if the string contains the given substring.
Parameters:
needle(String) — the substring to search for
Returns: Boolean — true if needle is present
fn trim() -> StringReturns the string with leading and trailing whitespace removed.
Returns: String — the trimmed string
replace
Section titled “replace”fn replace(old: String, new: String) -> StringReturns the string with all occurrences of old replaced with new.
Parameters:
old(String) — the substring to findnew(String) — the replacement string
Returns: String — the string with replacements applied
starts_with
Section titled “starts_with”fn starts_with(prefix: String) -> BooleanReturns true if the string starts with the given prefix.
Parameters:
prefix(String) — the prefix to check
Returns: Boolean — true if the string starts with prefix
ends_with
Section titled “ends_with”fn ends_with(suffix: String) -> BooleanReturns true if the string ends with the given suffix.
Parameters:
suffix(String) — the suffix to check
Returns: Boolean — true if the string ends with suffix
repeat
Section titled “repeat”fn repeat(n: Number) -> StringReturns a new string by repeating this string n times.
Parameters:
n(Number) — number of repetitions
Returns: String — the repeated string
fn iter() -> IteratorReturns an iterator over the characters.
Returns: Iterator — an iterator over the characters
concat
Section titled “concat”fn concat(array1: Array, array2: Array) -> ArrayConcatenates two arrays.
Parameters:
array1(Array) — first arrayarray2(Array) — second array
Returns: Array — a new array containing all elements from both arrays
filter
Section titled “filter”fn filter(array: Array, func: Function) -> ArraySelects elements from an array that satisfy a predicate.
Example:
filter([1, 2, 3, 4], fn(x) { x > 2; }) returns [3, 4]
Parameters:
array(Array) — the array to filterfunc(Function) — returns truthy/falsy for each element
Returns: Array — a new array of matching elements
fn fold(array: Array, initial: any, func: Function) -> anyReduces an array to a single value using an accumulator function.
Example:
fold([1, 2, 3], 0, fn(acc, x) { acc + x; }) returns 6
Parameters:
array(Array) — the array to reduceinitial(Any) — starting value for the accumulatorfunc(Function) — takes (accumulator, element), returns new accumulator
Returns: Any — the final accumulated value
length
Section titled “length”fn length(array: Array) -> NumberReturns the number of elements in an array.
Parameters:
array(Array) — the array to measure
Returns: Number — the element count
fn map(array: Array, func: Function) -> ArrayTransforms each element of an array using a function.
Example:
map([1, 2, 3], fn(x) { x * 2; }) returns [2, 4, 6]
Parameters:
array(Array) — the array to transformfunc(Function) — takes one element, returns the transformed value
Returns: Array — a new array of transformed elements
fn range(start_or_end: Number, end: Number = NUL) -> ArrayGenerates an array of sequential numbers.
range(3); // => #[0, 1, 2]range(2, 5); // => #[2, 3, 4]Parameters:
start_or_end(Number) — if called with one arg, this is the end (start=0); if called with two args, this is the startend(Number) — exclusive upper bound
Returns: Array — sequential numbers from start to end-1
fn slice(array: Array, start: Number, end: Number) -> ArrayExtracts a subarray from start index to end index.
Parameters:
array(Array) — the source arraystart(Number) — start index (inclusive, 0-based)end(Number) — end index (exclusive)
Returns: Array — the subarray