Skip to content

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).

fn Array(...items) -> Array

Creates 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

fn length() -> Number

Returns the number of elements.

Returns: Number — the element count

fn push(value: any) -> Array

Adds an element to the end of the array.

Parameters:

  • value (Any) — the element to add

Returns: Array — the array, for chaining

fn popFunction

Removes 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) -> Array

Returns 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

fn concat(other: Array) -> Array

Returns a new array with elements from both arrays.

Parameters:

  • other (Array) — array to append

Returns: Array — a new array with the elements of both

fn reverse() -> Array

Returns a new array with elements in reverse order.

Returns: Array — a new reversed array

fn contains(value: any) -> Boolean

Returns 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) -> Array

Applies a function to each element, returns a new array.

Parameters:

  • func (Function) — fn(element) -> new_element

Returns: Array — a new array of transformed elements

fn filter(func: Function) -> Array

Returns a new array with only elements satisfying the predicate.

Parameters:

  • func (Function) — fn(element) -> bool

Returns: Array — a new array of matching elements

fn reduce(func: Function, initial: any)

Reduces the array to a single value.

Parameters:

  • func (Function) — fn(accumulator, element) -> new_accumulator
  • initial (Any) — starting accumulator value

Returns: Any — the final accumulated value

fn iter() -> Iterator

Returns 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) -> Dict

Sets a key-value pair in place.

Parameters:

  • key (String | Number) — the key to set
  • value (Any) — the value to associate

Returns: Dict — the dict, for chaining

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() -> Array

Returns an Array of all keys.

Returns: Array — all keys

fn values() -> Array

Returns an Array of all values.

Returns: Array — all values

fn length() -> Number

Returns the number of entries.

Returns: Number — the entry count

fn contains_key(key: String or Number) -> Boolean

Returns true if the dict contains the given key.

Parameters:

  • key (String | Number) — the key to check

Returns: Boolean — true if key is present

fn entries() -> Array

Returns an Array of [key, value] pairs.

Returns: Array — one [key, value] pair per entry

fn merge(other: Dict) -> Dict

Returns 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) -> Dict

Transforms values using a function.

Parameters:

  • func (Function) — fn(key, value) -> new_value

Returns: Dict — a new dict with transformed values

fn filter(func: Function) -> Dict

Filters entries by predicate.

Parameters:

  • func (Function) — fn(key, value) -> bool

Returns: Dict — a new dict with matching entries

fn reduce(func: Function, initial: any)

Reduces entries to a single value.

Parameters:

  • func (Function) — fn(accumulator, key, value) -> new_accumulator
  • initial (Any) — starting accumulator value

Returns: Any — the final accumulated value

fn iter() -> Iterator

Returns an Iterator over the keys.

Returns: Iterator — an iterator over the keys

Lazy sequence of values with chainable transformations. Obtain from .iter() on arrays, strings, or patterns.

fn nextFunction

Returns the next value, or nil if exhausted.

Returns: Any — the next value, or nil if exhausted

fn take(n: Number) -> Iterator

Returns 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

fn collect() -> Array

Collects all remaining elements into an array.

Returns: Array — the remaining elements

fn skip(n: Number) -> Iterator

Returns 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() -> Number

Counts remaining elements (consumes the iterator).

Returns: Number — the count of remaining elements

fn step_by(step: Number) -> Iterator

Returns a lazy iterator yielding every nth element.

Parameters:

  • step (Number) — take every nth element

Returns: Iterator — a lazy iterator over every step-th element

fn enumerate() -> Iterator

Returns a lazy iterator yielding [index, value] pairs.

Returns: Iterator — a lazy iterator of [index, value] pairs

fn firstFunction

Returns the first element, or nil if empty.

Returns: Any — the first element, or nil if empty

fn lastFunction

Returns 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) -> Array

Applies a function to each element, returns an array.

Parameters:

  • func (Function) — fn(element) -> new_element

Returns: Array — a new array of transformed elements

fn filter(func: Function) -> Array

Filters 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) -> Boolean

Returns 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) -> Boolean

Returns 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 value
  • func (Function) — fn(accumulator, element) -> new_accumulator

Returns: Any — the final accumulated value

fn zip(other: Iterator) -> Iterator

Zips 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) -> Iterator

Chains another iterator after this one.

Parameters:

  • other (Iterator) — iterator to append

Returns: Iterator — a lazy iterator over both in sequence

fn flatten() -> Array

Flattens nested arrays into a single array.

Returns: Array — the flattened elements

Text value with Unicode support. Construct with literal syntax "hello".

fn length() -> Number

Returns the character count (Unicode-aware).

Returns: Number — the character count

fn uppercase() -> String

Returns the string converted to uppercase.

Returns: String — the uppercased string

fn lowercase() -> String

Returns the string converted to lowercase.

Returns: String — the lowercased string

fn substring(start: Number, end: Number) -> String

Returns 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) -> Array

Splits the string by a delimiter, returns an array of strings.

Parameters:

  • delimiter (String) — the string to split on

Returns: Array — the parts as Strings

fn contains(needle: String) -> Boolean

Returns 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() -> String

Returns the string with leading and trailing whitespace removed.

Returns: String — the trimmed string

fn replace(old: String, new: String) -> String

Returns the string with all occurrences of old replaced with new.

Parameters:

  • old (String) — the substring to find
  • new (String) — the replacement string

Returns: String — the string with replacements applied

fn starts_with(prefix: String) -> Boolean

Returns 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

fn ends_with(suffix: String) -> Boolean

Returns 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

fn repeat(n: Number) -> String

Returns a new string by repeating this string n times.

Parameters:

  • n (Number) — number of repetitions

Returns: String — the repeated string

fn iter() -> Iterator

Returns an iterator over the characters.

Returns: Iterator — an iterator over the characters

fn concat(array1: Array, array2: Array) -> Array

Concatenates two arrays.

Parameters:

  • array1 (Array) — first array
  • array2 (Array) — second array

Returns: Array — a new array containing all elements from both arrays

fn filter(array: Array, func: Function) -> Array

Selects 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 filter
  • func (Function) — returns truthy/falsy for each element

Returns: Array — a new array of matching elements

fn fold(array: Array, initial: any, func: Function) -> any

Reduces 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 reduce
  • initial (Any) — starting value for the accumulator
  • func (Function) — takes (accumulator, element), returns new accumulator

Returns: Any — the final accumulated value

fn length(array: Array) -> Number

Returns 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) -> Array

Transforms 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 transform
  • func (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) -> Array

Generates 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 start
  • end (Number) — exclusive upper bound

Returns: Array — sequential numbers from start to end-1

fn slice(array: Array, start: Number, end: Number) -> Array

Extracts a subarray from start index to end index.

Parameters:

  • array (Array) — the source array
  • start (Number) — start index (inclusive, 0-based)
  • end (Number) — end index (exclusive)

Returns: Array — the subarray