pub fn contains < T: Equatable > (self: const vector<T>, value: T) -> boolean
Does the vector hold value? Compared by content, as == compares every type; the empty vector holds nothing. The membership test a script asks of a list of names — changed.contains(path) — beside text's own contains.
pub fn min_of < T: Ordered > (v: const vector<T>) -> T?
Smallest element in a vector, or null when the vector is empty (the type is honest about the empty case). Works on any Ordered type (op <).
pub fn max_of < T: Ordered > (v: const vector<T>) -> T?
Largest element in a vector, or null when the vector is empty (the type is honest about the empty case). Works on any Ordered type (op <).
pub fn sum < T: Addable > (v: const vector<T>, init: T? = null) -> T
Sum of vector elements. Works on any Addable type. init is the identity to start from; leave it out and the element type's own zero is used (0, 0.0). Example: sum([10, 20, 12], 0) == 42 Example: sum([10, 20, 12]) == 42
pub fn reverse < T > (self: vector<T>)
Reverse a vector's elements in place: reverse(v) or v.reverse(). A method on vector, so a program may define its own reverse for its own types beside it.
pub fn reserve < T > (self: vector<T>, n: integer)
Give a vector room for n elements, so filling it does not grow it step by step: reserve(v, n) or v.reserve(n). Changes neither len(v) nor what is in it, and a count the vector already covers does nothing. A hash takes reserve(h, n) too.
pub fn insert < T > (self: vector<T>, index: integer, elem: T)
Insert elem at index, moving the elements from there one place up: insert(v, i, x) or v.insert(i, x). Both arguments are values before the vector grows, so an element read from the vector itself (v.insert(0, v[1])) is the one it was.
pub fn sort < T: Ordered > (self: vector<T>)
Sort a vector in place, ascending: sort(v) or v.sort(). Takes any element with a < (Ordered) — a struct defining op < sorts by it — and is stable: elements that compare equal keep their order. A null element sorts first.
pub fn sort_by < T, K: Ordered > (self: vector<T>, key: fn(T) -> K)
Sort a vector in place by a key, ascending: v.sort_by(fn(d: Date) -> integer { d.ms }). The key is any Ordered value — a number or a text — so this is how a struct sorts (C132). Stable, like sort: elements with equal keys keep their order. key is called once per element.
pub fn min_by < T, K: Ordered > (self: vector<T>, key: fn(T) -> K) -> T?
The element with the smallest key, or null when the vector is empty: v.min_by(fn(d: Date) -> integer { d.ms }). Of several with that key, the FIRST.
pub fn max_by < T, K: Ordered > (self: vector<T>, key: fn(T) -> K) -> T?
The element with the largest key, or null when the vector is empty: v.max_by(fn(d: Date) -> integer { d.ms }). Of several with that key, the FIRST.
pub fn sum_by < T, K: Addable > (self: vector<T>, key: fn(T) -> K, init: K? = null) -> K
The sum of a key over the elements: v.sum_by(fn(o: Order) -> float { o.price }). The key is any Addable value; init is the identity to start from, and left out it is the key type's own zero (0, 0.0), so an empty vector sums to it.
pub fn filter < T > (self: vector<T>, f: fn(T) -> boolean) -> vector<T>
Keep the elements f answers true for, in order: filter(v, f) or v.filter(f).
pub fn map < T, U > (self: vector<T>, f: fn(T) -> U) -> vector<U>
What f answers for each element, in order: map(v, f) or v.map(f) — the result's element is what f returns, so a map can change the element type.
pub fn reduce < T, U > (self: vector<T>, init: U, f: fn(U, T) -> U) -> U
Fold the elements into one value, left to right, from init: reduce(v, init, f) or v.reduce(init, f). Any accumulator: a number, a text, a struct, any collection.
pub fn sum_of(v: const vector<integer>) -> integer
Sum of all integer elements. Returns 0 for an empty vector. Superseded by the general sum(v, init); kept as a shim over it (the old form keeps working). sum_of(v) == sum(v, 0).
pub interface Walkable {
fn children(self: Self) -> vector<Self>
}
A type that can be walked as a tree. Declaring fn children(self: T) -> vector<T> is the whole contract — that bare function is what makes T walkable, with nothing to register and no base type to inherit from. tree_walk is what consumes it.
pub fn tree_walk < T: Walkable > (wk_root: T, cap: integer) -> vector<T>
Every node reachable from wk_root in breadth-first order: the root, then its children, then theirs. T is any type declaring fn children(self: T) -> vector<T> — writing that bare function is what makes a type Walkable, with nothing to register.
cap bounds the ANSWER, not just the effort: at most cap nodes come back (the root alone when cap is 0 or 1) and the walk stops there. That bound is what makes this total on a structure that has a cycle or no end, so pass a count you would accept as an answer rather than a number picked to be large.
Nodes are not de-duplicated — the walk carries no visited set, so a node reached by two parents is returned twice.