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.

Map

Balanced ordered tree of 'Compare' keys and 'Base' values

Example

function : Example() ~ Nil {
   # insert elements
   map := Collection.Map->New()<IntRef, String>;
   map->Insert(415, "San Francisco");
   map->Insert(510, "Oakland");
   map->Insert(925, "East Bay");

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

   # get value by key
   map->Find(510)->PrintLine();

   # get key/values
   key_values := map->GetKeyValues()<Pair<IntRef, String>>;
   each(key_value := key_values) {
      key_value->GetFirst()->PrintLine();
   };

   # get values
   values := map->GetValues()<String>;
   each(value := values) {
      value->PrintLine();
   };

   # check for key
   map->Has(408)->PrintLine();
}

Operations

Dict # function

Converts a vector pairs to a map

function : Dict(pairs:Vector<Collection.Tuple.Pair<K,V>>) ~ Map<K,V>

Parameters

NameTypeDescription
pairsVector<CollectionTuplePair<K,V>>vector of pairs

Return

TypeDescription
Map<K,V>mapped pairs

Example

pairs := Collection.Vector->New()<Collection.Tuple.Pair<String, IntRef>>;
pairs->AddBack(Collection.Tuple.Pair->New("one", IntRef->New(1))<String, IntRef>);
pairs->AddBack(Collection.Tuple.Pair->New("two", IntRef->New(2))<String, IntRef>);
map := Collection.Map->Dict(pairs)<String, IntRef>;
map->Find("one")->PrintLine(); # 1

Each #

Function called for each element

method : public : Each(f:(K,V)~Nil) ~ Map<K,V>

Parameters

NameTypeDescription
f(K,V)~Nilfunction called

Example

map := Collection.Map->New()<String, IntRef>;
map->Insert("a", IntRef->New(1)); map->Insert("b", IntRef->New(2));
map->Each(\(String, IntRef) ~ Nil : (k, v) => "{$k}={$v}"->PrintLine());

Empty #

Clears the map

method : public : Empty() ~ Nil

Example

map := Collection.Map->New()<String, IntRef>;
map->Insert("a", IntRef->New(1));
map->Empty();
map->IsEmpty()->PrintLine(); # true

Filter #

Uses the given function to filter out values

method : public : Filter(f:(K)~Bool) ~ Map<K,V>

Parameters

NameTypeDescription
f(K)~Boolfunction to use a filter. If the function evaluates to true the value is added to the collection.

Return

TypeDescription
Map<K,V>filtered map

Example

map := Collection.Map->New()<String, IntRef>;
map->Insert("a", IntRef->New(1)); map->Insert("b", IntRef->New(2));
filtered := map->Filter(\(String) ~ Bool : (k) => k->Equals("a"))<String, IntRef>;
filtered->Size()->PrintLine(); # 1

Find #

Searches for a value in a map

method : public : Find(key:K) ~ V

Parameters

NameTypeDescription
keyKsearch key

Return

TypeDescription
Vfound value, Nil if not found

Example

map := Collection.Map->New()<String, IntRef>;
map->Insert("pi", IntRef->New(3));
map->Find("pi")->PrintLine();   # 3
map->Find("e")->PrintLine();    # (Nil)

GetKeyValues #

Get a collection of key-value pairs

method : public : GetKeyValues() ~ Collection.Vector<Pair<K,V>>

Return

TypeDescription
CollectionVector<Pair<K,V>>vector of key-value pairs

Example

map := Collection.Map->New()<String, IntRef>;
map->Insert("a", IntRef->New(1)); map->Insert("b", IntRef->New(2));
kvs := map->GetKeyValues()<Collection.Pair<String, IntRef>>;
each(kv := kvs) { "{$kv->GetFirst()}={$kv->GetSecond()}"->PrintLine(); }

GetKeys #

Get a collection of keys

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

Return

TypeDescription
CollectionVector<K>vector of keys

Example

map := Collection.Map->New()<String, IntRef>;
map->Insert("x", IntRef->New(10)); map->Insert("y", IntRef->New(20));
keys := map->GetKeys()<String>;
each(k := keys) { k->PrintLine(); }

GetValues #

Gets a collection of values

method : public : GetValues() ~ Collection.Vector<V>

Return

TypeDescription
CollectionVector<V>vector of values

Example

map := Collection.Map->New()<String, IntRef>;
map->Insert("p", IntRef->New(3)); map->Insert("q", IntRef->New(4));
values := map->GetValues()<IntRef>;
each(v := values) { v->PrintLine(); }

Has #

Checks for a value in a map

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

Parameters

NameTypeDescription
keyKsearch key

Return

TypeDescription
Booltrue if found, false otherwise

Example

map := Collection.Map->New()<String, IntRef>;
map->Insert("cat", IntRef->New(1));
map->Has("cat")->PrintLine(); # true
map->Has("dog")->PrintLine(); # false

Insert #

Inserts a value into the map

method : public : Insert(key:K, value:V) ~ Nil

Parameters

NameTypeDescription
keyKkey
valueVvalue

Example

map := Collection.Map->New()<String, IntRef>;
map->Insert("city", IntRef->New(42));
map->Find("city")->PrintLine(); # 42

IsEmpty #

Checks to see if the map is empty

method : public : IsEmpty() ~ Bool

Return

TypeDescription
Booltrue if empty, false otherwise

Example

map := Collection.Map->New()<String, IntRef>;
map->IsEmpty()->PrintLine(); # true
map->Insert("x", IntRef->New(9));
map->IsEmpty()->PrintLine(); # false

New # constructor

Default constructor

New()

Example

map := Collection.Map->New()<String, IntRef>;
map->Insert("alpha", IntRef->New(1));
map->Size()->PrintLine(); # 1

Reduce #

Uses the given function to reduce the values

method : public : Reduce(a:K, f:(K,K)~K) ~ K

Parameters

NameTypeDescription
aKinitial value (i.e. accumulator)
f(K,K)~Kfunction to use a reduce

Return

TypeDescription
Kreduced value

Example

map := Collection.Map->New()<String, IntRef>;
map->Insert("a", IntRef->New(0)); map->Insert("b", IntRef->New(0));
concat := map->Reduce("", \(String, String) ~ String : (acc, k) => "{$acc}{$k}");
concat->PrintLine(); # ab

Remove #

Removes a value from the map

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

Parameters

NameTypeDescription
keyKkey for value to remove

Example

map := Collection.Map->New()<String, IntRef>;
map->Insert("tmp", IntRef->New(0));
map->Remove("tmp")->PrintLine();  # true
map->Has("tmp")->PrintLine();     # false

Size #

Size of queue

method : public : Size() ~ Int

Return

TypeDescription
Intsize of queue

Example

map := Collection.Map->New()<String, IntRef>;
map->Insert("a", IntRef->New(1)); map->Insert("b", IntRef->New(2));
map->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

map := Collection.Map->New()<String, IntRef>;
map->Insert("a", IntRef->New(1)); map->Insert("b", IntRef->New(2));
map->ToString()->PrintLine(); # [(a:1),(b:2)]