[]T is Nova's built-in dynamic array (D27 syntax, D32 (ptr, len, cap) representation). The built-in API — len, cap, push, pop, with_capacity, [i] — is compiler-provided. This module adds functional combinators via D35 receiver-generics.
let nums []int = [1, 2, 3, 4, 5]
let squared = nums.map(|x| x * x)
let evens = nums.filter(|x| x % 2 == 0)
let total = nums.fold(0, |acc, x| acc + x)
assert(total == 15)
map
stable since 0.1fn []T @map[U](f fn(T) -> U) -> []U
Applies f to each element and returns a new array []U. The method-level generic [U] (D42) lets a single []T method produce any target type.
Examples
let v []int = [1, 2, 3]
assert(v.map(|x| x * 2) == [2, 4, 6])
filter
stable since 0.1fn []T @filter(pred fn(T) -> bool) -> []T
Returns a new array containing only elements where pred(x) is true. Preserves order. Original is not mutated.
Examples
let v []int = [1, 2, 3, 4, 5]
assert(v.filter(|x| x % 2 == 0) == [2, 4])
fold
stable since 0.1fn []T @fold[Acc](init Acc, f fn(Acc, T) -> Acc) -> Acc
Left fold (reduce). Starts with accumulator init and applies f(acc, x) for each element. The method-level generic [Acc] is independent of T, so you can fold an []int into a str, etc.
Examples
let v []int = [1, 2, 3, 4]
assert(v.fold(0, |acc, x| acc + x) == 10)
any
stable since 0.1fn []T @any(pred fn(T) -> bool) -> bool
Returns true if at least one element satisfies pred. Short-circuits on the first match. Returns false on an empty array.
Examples
let v []int = [1, 2, 3]
assert(v.any(|x| x > 2))
assert(!v.any(|x| x > 10))
all
stable since 0.1fn []T @all(pred fn(T) -> bool) -> bool
Returns true if every element satisfies pred. Short-circuits on the first mismatch. Vacuous truth: returns true on an empty array.
Examples
let v []int = [2, 4, 6]
assert(v.all(|x| x % 2 == 0))
first
stable since 0.1fn []T @first() -> Option[T]
Returns the first element wrapped in Some(T), or None if the array is empty.
Examples
let v []int = [10, 20, 30]
assert(v.first() == Some(10))
assert([]int.new().first() == None)
last
stable since 0.1fn []T @last() -> Option[T]
Returns the last element wrapped in Some(T), or None if the array is empty.
Examples
let v []int = [10, 20, 30]
assert(v.last() == Some(30))
assert([]int.new().last() == None)