Skip to content

Choose a collection

Collections hold several values. Choose the type based on how you will read and change those values.

Import: import system.collections;

You need… Use
Items you can read by position List
Values you look up by a key Map
Keys kept in sorted order SortedMap
Unique values Set
Items processed in arrival order Queue
The most recently added item first Stack
The smallest or highest-priority item first PriorityQueue
Filtering and transforming items Queries and Seq

Guides in this section

Start with a list

import system;
import system.collections;

fun main() {
    let names: List<string> = ["Ada", "Sam"];
    names.push("Lee");
    for (let name in names) {
        System.println(name);
    }
}

This prints each name on a separate line. The List<string> type tells Dream to make a growable list. Without that expected type, square brackets create a fixed array.

Typed {value, value} creates a set, and typed {key: value} creates a map. Empty collections need a type, such as let names: Set<string> = {};.

Missing items and positions

Check each collection's result type before assuming an item exists. Map lookups and queue removals can return None. List indexing uses a position and stops the program if that position is outside the list.

See Option and Result for handling absence and the API catalog for all public members.