prelude.Array
Part of prelude.
let Array.is_empty (xs: Array[T]): Bool
Whether the array has no elements.
let Array.concat (a: Array[T]) (b: Array[T]): Array[T]
A new array with b's elements after a's. Neither input is changed.
let Array.contains (xs: Array[T]) (needle: T): Bool
Whether any element equals needle, compared structurally.
let Array.any (xs: Array[T]) (f: (T) -> Bool): Bool
Whether f holds for at least one element. Stops at the first that passes; false for an empty array.
let Array.slice (xs: Array[T]) (start: Int) (end: Int): Array[T]
The elements from start up to but NOT including end.
Out-of-range bounds are clamped rather than an error, and a start past end gives an empty array — so slicing near the end of an array needs no arithmetic to stay safe.
let Array.reverse (xs: Array[T]): Array[T]
A new array in the opposite order.
let Array.all (xs: Array[T]) (f: (T) -> Bool): Bool
Whether f holds for every element. Stops at the first that fails; TRUE for an empty array, which is the convention everywhere and still surprises people.
let Array.find (xs: Array[T]) (f: (T) -> Bool): Option[T]
The first element f accepts, or None.
let Array.find_index (xs: Array[T]) (f: (T) -> Bool): Option[Int]
The index of the first element f accepts, or None.
let Array.index_of (xs: Array[T]) (needle: T): Option[Int]
The index of the first element equal to needle, or None.
let Array.first (xs: Array[T]): Option[T]
The first element, or None when the array is empty.
let Array.last (xs: Array[T]): Option[T]
The last element, or None when the array is empty.
let Array.take (xs: Array[T]) (n: Int): Array[T]
The first n elements, or all of them if there are fewer. Never an error.
let Array.drop (xs: Array[T]) (n: Int): Array[T]
Everything after the first n elements, or nothing if there are fewer.
let Array.sum_int (xs: Array[Int]): Int
The sum, which OVERFLOWS like any other addition and stops the program rather than wrapping.
let Array.sum_float (xs: Array[Float]): Float
The sum, left to right. Floating-point addition is not associative, so a different order can give a different last digit.
let Array.join (parts: Array[String]) (sep: String): String
Namespaced under Array, not String, since 2026-08-25: both take an Array[String]. String. used to mean two different things, "first parameter is a String" for most of it and "produces a String" for these two, and x.f(a) = T.f(x, a) needs it to mean exactly one. parts.join(", ") now works and reads the right way round.
let Array.sort_by (arr: Array[T]) (le: (T, T) -> Bool): Array[T]
Sorted by a \"less than or equal\" predicate.
STABLE: elements le considers equivalent keep their original order, which is what makes sorting by one key and then another produce the ordering people expect.
let Array.sort_int (arr: Array[Int]): Array[Int]
Sorted ascending.
let Array.sort_float (arr: Array[Float]): Array[Float]
Sorted ascending. NaN does not compare, so an array containing one has no meaningful order.
let Array.zip (a: Array[T]) (b: Array[U]): Array[Zipped[T, U]]
Pairs elements positionally, stopping at the shorter array.
let Array.concat_all (parts: Array[String]): String
Joins in ONE allocation. Building a large string by repeated .concat is quadratic; this is what the compiler's own emitter uses for anything that accumulates.
let Array.sort_string (arr: Array[String]): Array[String]
Sorted by BYTE order, not by any locale's alphabet — so uppercase sorts before lowercase, and accented letters sort after z.