v2026.11.3
All Bundles
Bundle

Generic collections library: Vector (dynamic array), List (linked list), Map (ordered binary tree, O(log n)), Hash (hash table), Set, HashSet, SetHash, MultiMap, MultiHash, Stack, Queue, and Pair. Provides typed iteration, sorting, filtering, and functional operations (Reduce, Any, All). Compile with -lib gen_collect.

Set

Ordered set of generic objects

Example

# insert elements
set := Collection.Set->New()<String>;
set->Insert("San Francisco");
set->Insert("Oakland");
set->Insert("East Bay");

# get size
set->Size()->PrintLine();

# get value by key
set->Has("Oakland")->PrintLine();

Operations

Add #

Adds a key to the set; the same as Insert, but says whether it was new

method : public : Add(key:K) ~ Bool

Parameters

NameTypeDescription
keyKkey

Return

TypeDescription
Booltrue if added, false if it was already in the set (or is Nil)

Example

set := Collection.Set->New()<String>;
set->Add("apple")->PrintLine(); # true
set->Add("apple")->PrintLine(); # false

Difference #

Elements in this set that are not in the other set. Neither set is changed.

method : public : Difference(that:Set<K>) ~ Set<K>

Parameters

NameTypeDescription
thatSet<K>other set (Nil counts as empty)

Return

TypeDescription
Set<K>new set

Example

a := Collection.Set->New()<IntRef>;
a->Insert(1); a->Insert(2); a->Insert(3);
b := Collection.Set->New()<IntRef>;
b->Insert(2); b->Insert(3); b->Insert(4);
a->Difference(b)->Has(1)->PrintLine(); # true

Each #

Calls a function for each element

method : public : Each(f:(K)~Nil) ~ Set<K>

Parameters

NameTypeDescription
f(K)~Nilfunction called

Return

TypeDescription
Set<K>this set

Example

set := Collection.Set->New()<String>;
set->Insert("x"); set->Insert("y");
set->Each(\(s) => { s->PrintLine(); });

Empty #

Clears the set

method : public : Empty() ~ Nil

Example

set := Collection.Set->New()<String>;
set->Insert("item");
set->Empty();
set->IsEmpty()->PrintLine(); # true

Filter #

Keeps the elements a function accepts. The set is not changed.

method : public : Filter(f:(K)~Bool) ~ Set<K>

Parameters

NameTypeDescription
f(K)~Boolfunction that returns true for each element to keep

Return

TypeDescription
Set<K>new set

Example

set := Collection.Set->New()<String>;
set->Insert("apple"); set->Insert("kiwi");
set->Filter(\(s) => s->Size() > 4)->Size()->PrintLine(); # 1

GetKeys #

Get a collection of keys

method : public : GetKeys() ~ Vector<K>

Return

TypeDescription
Vector<K>vector of keys

Example

set := Collection.Set->New()<String>;
set->Insert("a"); set->Insert("b");
keys := set->GetKeys()<String>;
each(k := keys) { k->PrintLine(); }

Has #

Checks for key in set

method : public : Has(key:K) ~ Bool

Parameters

NameTypeDescription
keyKsearch key

Return

TypeDescription
Booltrue if found, false otherwise

Example

set := Collection.Set->New()<String>;
set->Insert("found");
set->Has("found")->PrintLine();   # true
set->Has("missing")->PrintLine(); # false

Insert #

Inserts a key into the set

method : public : Insert(key:K) ~ Nil

Parameters

NameTypeDescription
keyKkey

Example

set := Collection.Set->New()<String>;
set->Insert("apple");
set->Insert("apple"); # duplicate ignored
set->Size()->PrintLine(); # 1

Intersect #

Elements in both this set and the other set. Neither set is changed.

method : public : Intersect(that:Set<K>) ~ Set<K>

Parameters

NameTypeDescription
thatSet<K>other set (Nil counts as empty)

Return

TypeDescription
Set<K>new set

Example

a := Collection.Set->New()<IntRef>;
a->Insert(1); a->Insert(2); a->Insert(3);
b := Collection.Set->New()<IntRef>;
b->Insert(2); b->Insert(3); b->Insert(4);
a->Intersect(b)->Size()->PrintLine(); # 2

IsEmpty #

Checks to see if the set is empty

method : public : IsEmpty() ~ Bool

Return

TypeDescription
Booltrue if empty, false otherwise

Example

set := Collection.Set->New()<String>;
set->IsEmpty()->PrintLine(); # true
set->Insert("z");
set->IsEmpty()->PrintLine(); # false

IsSubset #

Checks that every element of this set is in the other set. The empty set is a subset of every set.

method : public : IsSubset(that:Set<K>) ~ Bool

Parameters

NameTypeDescription
thatSet<K>other set (Nil counts as empty)

Return

TypeDescription
Booltrue if this set is a subset of the other, false otherwise

Example

a := Collection.Set->New()<IntRef>;
a->Insert(1); a->Insert(2); a->Insert(3);
b := Collection.Set->New()<IntRef>;
b->Insert(2); b->Insert(3); b->Insert(4);
a->Intersect(b)->IsSubset(b)->PrintLine(); # true
a->IsSubset(b)->PrintLine(); # false

IsSuperset #

Checks that every element of the other set is in this set

method : public : IsSuperset(that:Set<K>) ~ Bool

Parameters

NameTypeDescription
thatSet<K>other set (Nil counts as empty)

Return

TypeDescription
Booltrue if this set is a superset of the other, false otherwise

Example

a := Collection.Set->New()<IntRef>;
a->Insert(1); a->Insert(2); a->Insert(3);
b := Collection.Set->New()<IntRef>;
b->Insert(2); b->Insert(3); b->Insert(4);
a->Union(b)->IsSuperset(a)->PrintLine(); # true

New # constructor

Default constructor

New()

Example

set := Collection.Set->New()<String>;
set->Insert("hello");
set->Size()->PrintLine(); # 1

Remove #

Removes a key from the set

method : public : Remove(key:K) ~ Bool

Parameters

NameTypeDescription
keyKkey for value to remove

Return

TypeDescription
Booltrue if removed, false otherwise

Example

set := Collection.Set->New()<String>;
set->Insert("go");
set->Remove("go")->PrintLine();  # true
set->Has("go")->PrintLine();     # false

Size #

Size of map

method : public : Size() ~ Int

Return

TypeDescription
Intsize of queue

Example

set := Collection.Set->New()<String>;
set->Insert("a"); set->Insert("b"); set->Insert("c");
set->Size()->PrintLine(); # 3

SymmetricDifference #

Elements in exactly one of the two sets. Neither set is changed.

method : public : SymmetricDifference(that:Set<K>) ~ Set<K>

Parameters

NameTypeDescription
thatSet<K>other set (Nil counts as empty)

Return

TypeDescription
Set<K>new set

Example

a := Collection.Set->New()<IntRef>;
a->Insert(1); a->Insert(2); a->Insert(3);
b := Collection.Set->New()<IntRef>;
b->Insert(2); b->Insert(3); b->Insert(4);
a->SymmetricDifference(b)->Size()->PrintLine(); # 2 (1 and 4)

ToArray #

Gets all elements as an array

method : public : ToArray() ~ K[]

Return

TypeDescription
K[]array of elements

Example

set := Collection.Set->New()<String>;
set->Insert("p"); set->Insert("q");
set->ToArray()->Size()->PrintLine(); # 2

ToString #

Formats the collection into a string. If an element implements the 'Stringify' interface, it's 'ToString()' is called.

method : public : ToString() ~ String

Return

TypeDescription
Stringstring representation

Example

set := Collection.Set->New()<String>;
set->Insert("x"); set->Insert("y");
set->ToString()->PrintLine(); # [x,y]

ToVector #

Gets all elements as a vector; the same as GetKeys

method : public : ToVector() ~ Vector<K>

Return

TypeDescription
Vector<K>vector of elements

Example

set := Collection.Set->New()<String>;
set->Insert("x"); set->Insert("y");
set->ToVector()->Size()->PrintLine(); # 2

Union #

Elements in this set, the other set, or both. Neither set is changed.

method : public : Union(that:Set<K>) ~ Set<K>

Parameters

NameTypeDescription
thatSet<K>other set (Nil counts as empty)

Return

TypeDescription
Set<K>new set

Example

a := Collection.Set->New()<IntRef>;
a->Insert(1); a->Insert(2); a->Insert(3);
b := Collection.Set->New()<IntRef>;
b->Insert(2); b->Insert(3); b->Insert(4);
a->Union(b)->Size()->PrintLine(); # 4