Skip to content

std/collection

List, Stack, Queue, HashSet, and HashMap are in the automatic prelude. Import the module explicitly when using a module namespace:

import "std/collection" as collection;

List<T> is a linked collection:

var queue = new List<String>();
queue.push("compile");
queue.push("link");
println(queue.popFront());
println(toString(queue.len()));
GroupMethods
Inspectlen(), isEmpty(), front(), back(), at(index)
Addpush(value), pushFront(value), insert(index, value)
Changeset(index, value)
RemovepopFront(), popBack(), removeAt(index), clear()

Invalid indices and operations that require an element from an empty list call panic.

HashMap<V> stores values under String keys:

var ports = new HashMap<Int>();
ports.put("http", 80);
ports.put("https", 443);
var secure = ports.getOr("https", 0);

Methods: len(), isEmpty(), clear(), contains(key), put(key, value), get(key), getOr(key, fallback), remove(key), and bucketCapacity().

get calls panic when the key is absent. Use contains or getOr when absence is expected.

Stack<T> is last-in, first-out. Its methods are len(), isEmpty(), clear(), push(value), pop(), and peek().

Queue<T> is first-in, first-out. Its methods are len(), isEmpty(), clear(), enqueue(value), dequeue(), and peek().

pop, peek, and dequeue call panic on an empty collection.

HashSet stores unique String keys. Its methods are len(), isEmpty(), clear(), add(key), contains(key), and remove(key). add and remove return whether the set changed.