Skip to content

std/collection

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