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.

Vector

Growable generic array

Example

function : Example() ~ Nil {
   # insert elements
   vector := Collection.Vector->New()<IntRef>;
   vector->AddBack(4);
   vector->AddBack(1);
   vector->AddBack(5);
   vector->AddBack(1);
   vector->AddBack(0);
   
   # remove last item
   vector->RemoveBack();
   
   # get size
   vector->Size()->PrintLine();
   
   # get elements
   (vector->Get(0) + vector->Get(1))->PrintLine();
   
   # print all items with a loop
   each(item := vector) {
   item->PrintLine();
   };
   
   # print all items with a function
   vector->Each(Show(IntRef) ~ Nil);
}

function : Show(value : IntRef) ~ Nil {
   value->PrintLine();
}

Operations

AddAll #

Appends every value of another vector (the values are shared, not copied)

method : public : AddAll(that:Vector<H>) ~ Nil

Parameters

NameTypeDescription
thatVector<H>vector to append, may be this vector

Example

v := Collection.Vector->New()<String>;
v->AddBack("a");
v->AddAll(v);
v->Size()->PrintLine(); # 2

AddBack #

Adds a value to the end

method : public : AddBack(value:H) ~ Nil

Parameters

NameTypeDescription
valueHvalue to append

Example

v := Collection.Vector->New()<String>;
v->AddBack("first");
v->AddBack("second");
v->Size()->PrintLine(); # 2

All #

Checks if all elements match the predicate

method : public : All(f:(H)~Bool) ~ Bool

Parameters

NameTypeDescription
f(H)~Boolpredicate function

Return

TypeDescription
Booltrue if all elements match, false otherwise

Example

v := Collection.Vector->New()<String>;
v->AddBack("hello"); v->AddBack("world");
v->All(\(String) ~ Bool : (s) => s->Size() > 3)->PrintLine(); # true

Any #

Checks if any element matches the predicate

method : public : Any(f:(H)~Bool) ~ Bool

Parameters

NameTypeDescription
f(H)~Boolpredicate function

Return

TypeDescription
Booltrue if any element matches, false otherwise

Example

v := Collection.Vector->New()<String>;
v->AddBack("hello"); v->AddBack("world");
v->Any(\(String) ~ Bool : (s) => s->StartsWith("h"))->PrintLine(); # true

Compress #

Compresses the Vector freeing unused memory

method : public : Compress() ~ Nil

Example

v := Collection.Vector->New()<String>;
v->AddBack("x"); v->AddBack("y");
v->Compress();
v->Size()->PrintLine(); # 2

Count #

Counts elements matching the predicate

method : public : Count(f:(H)~Bool) ~ Int

Parameters

NameTypeDescription
f(H)~Boolpredicate function

Return

TypeDescription
Intcount of matching elements

Example

v := Collection.Vector->New()<String>;
v->AddBack("apple"); v->AddBack("apricot"); v->AddBack("banana");
v->Count(\(String) ~ Bool : (s) => s->StartsWith("a"))->PrintLine(); # 2

Each #

Function called for each element

method : public : Each(f:(H)~Nil) ~ Vector<H>

Parameters

NameTypeDescription
f(H)~Nilfunction called

Example

v := Collection.Vector->New()<String>;
v->AddBack("a"); v->AddBack("b");
v->Each(\(String) ~ Nil : (s) => s->PrintLine());

Empty #

Clears the vector

method : public : Empty() ~ Nil

Example

v := Collection.Vector->New()<String>;
v->AddBack("x");
v->Empty();
v->IsEmpty()->PrintLine(); # true

Filter #

Uses the given function to filter out values

method : public : Filter(f:(H)~Bool) ~ Vector<H>

Parameters

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

Return

TypeDescription
Vector<H>filtered vector

Example

v := Collection.Vector->New()<String>;
v->AddBack("apple"); v->AddBack("banana"); v->AddBack("avocado");
filtered := v->Filter(\(String) ~ Bool : (s) => s->StartsWith("a"));
filtered->Size()->PrintLine(); # 2

FindFirst #

Finds the first element matching the predicate

method : public : FindFirst(f:(H)~Bool) ~ H

Parameters

NameTypeDescription
f(H)~Boolpredicate function

Return

TypeDescription
Hfirst matching element, or Nil if not found

Example

v := Collection.Vector->New()<String>;
v->AddBack("apple"); v->AddBack("banana");
v->FindFirst(\(String) ~ Bool : (s) => s->StartsWith("b"))->PrintLine(); # banana

FindIndex #

Finds the index of the first element matching the predicate

method : public : FindIndex(f:(H)~Bool) ~ Int

Parameters

NameTypeDescription
f(H)~Boolpredicate function

Return

TypeDescription
Intindex of first matching element, or -1 if not found

Example

v := Collection.Vector->New()<String>;
v->AddBack("apple"); v->AddBack("banana");
v->FindIndex(\(String) ~ Bool : (s) => s->StartsWith("b"))->PrintLine(); # 1

First #

Gets the first value

method : public : First() ~ H

Return

TypeDescription
Hfirst value, or Nil if not set

Example

v := Collection.Vector->New()<String>;
v->AddBack("first"); v->AddBack("second");
v->First()->PrintLine(); # first

Get #

Gets an indexed value

method : public : Get(index:Int) ~ H

Parameters

NameTypeDescription
indexIntindex

Return

TypeDescription
Hvalue, or Nil if invalid index

Example

v := Collection.Vector->New()<String>;
v->AddBack("a"); v->AddBack("b");
v->Get(0)->PrintLine(); # a
v->Get(1)->PrintLine(); # b

Insert #

Inserts a value at an index, shifting the values at and after it up by one

method : public : Insert(index:Int, value:H) ~ Bool

Parameters

NameTypeDescription
indexIntposition to insert at (0 to Size(); Size() appends)
valueHvalue to insert

Return

TypeDescription
Booltrue if inserted, false if the index is out of range

Example

v := Collection.Vector->New()<String>;
v->AddBack("a"); v->AddBack("c");
v->Insert(1, "b")->PrintLine(); # true
v->Size()->PrintLine();           # 3

IsEmpty #

Checks to see if the vector is empty

method : public : IsEmpty() ~ Bool

Return

TypeDescription
Booltrue if empty, false otherwise

Example

v := Collection.Vector->New()<String>;
v->IsEmpty()->PrintLine(); # true
v->AddBack("x");
v->IsEmpty()->PrintLine(); # false

Last #

Gets the last value

method : public : Last() ~ H

Return

TypeDescription
Hlast value, or Nil if not set

Example

v := Collection.Vector->New()<String>;
v->AddBack("a"); v->AddBack("b");
v->Last()->PrintLine(); # b

Limit #

Returns a limited list

method : public : Limit(l:Int) ~ Vector<H>

Parameters

NameTypeDescription
lIntlimit

Return

TypeDescription
Vector<H>limited list

Example

v := Collection.Vector->New()<String>;
v->AddBack("a"); v->AddBack("b"); v->AddBack("c");
first2 := v->Limit(2);
first2->Size()->PrintLine(); # 2

Map #

Maps the given function to each value in the vector

method : public : Map<R>(f:(H)~R) ~ Vector<R>

Parameters

NameTypeDescription
f(H)~Rfunction to apply

Return

TypeDescription
Vector<R>newly calculated vector

Example

v := Collection.Vector->New()<String>;
v->AddBack("hello"); v->AddBack("world");
upper := v->Map(\(String) ~ String : (s) => s->ToUpper());
upper->Get(0)->PrintLine(); # HELLO
lengths := v->Map(\(String) ~ IntRef : (s) => IntRef->New(s->Size())); # a Vector<IntRef>

New # constructor

Default constructor

New()

Example

v := Collection.Vector->New()<String>;
v->AddBack("hello");
v->Size()->PrintLine(); # 1

New # constructor

Copy constructor

New(values:H[])

Parameters

NameTypeDescription
valuesH[]values to copy

Example

arr := String->New[2];
arr[0] := "a"; arr[1] := "b";
v := Collection.Vector->New(arr)<String>;
v->Size()->PrintLine(); # 2

New # constructor

Copy constructor

New(values:Vector<H>)

Parameters

NameTypeDescription
valuesVector<H>values to copy

Example

src := Collection.Vector->New()<String>;
src->AddBack("x");
copy := Collection.Vector->New(src)<String>;
copy->Get(0)->PrintLine(); # x

Reduce #

Uses the given function to reduce the values

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

Parameters

NameTypeDescription
aHinitial value (i.e. accumulator)
f(H,H)~Hfunction to use a reduce

Return

TypeDescription
Hreduced value

Example

v := Collection.Vector->New()<String>;
v->AddBack("a"); v->AddBack("b"); v->AddBack("c");
joined := v->Reduce("", \(String, String) ~ String : (acc, s) => acc + s);
joined->PrintLine(); # abc

Remove #

Removes an indexed value

method : public : Remove(i:Int) ~ H

Parameters

NameTypeDescription
iIntindex

Return

TypeDescription
Hvalue

Example

v := Collection.Vector->New()<String>;
v->AddBack("a"); v->AddBack("b"); v->AddBack("c");
v->Remove(1)->PrintLine(); # b
v->Size()->PrintLine();    # 2

RemoveBack #

Removes the last value

method : public : RemoveBack() ~ H

Return

TypeDescription
Hvalue

Example

v := Collection.Vector->New()<String>;
v->AddBack("a"); v->AddBack("b");
v->RemoveBack()->PrintLine(); # b
v->Size()->PrintLine();       # 1

Reverse #

Reverses element order

method : public : Reverse() ~ Vector<H>

Return

TypeDescription
Vector<H>reversed vector, if the vector is empty or hold 1 item then the original list is returned

Example

v := Collection.Vector->New()<String>;
v->AddBack("a"); v->AddBack("b"); v->AddBack("c");
rev := v->Reverse();
rev->Get(0)->PrintLine(); # c

Set #

Sets an indexed value

method : public : Set(value:H, index:Int) ~ Bool

Parameters

NameTypeDescription
valueHvalue
indexIntindex

Example

v := Collection.Vector->New()<String>;
v->AddBack("old");
v->Set("new", 0)->PrintLine(); # true
v->Get(0)->PrintLine();        # new

Size #

Size of vector

method : public : Size() ~ Int

Return

TypeDescription
Intsize of vector

Example

v := Collection.Vector->New()<String>;
v->AddBack("a"); v->AddBack("b");
v->Size()->PrintLine(); # 2

Slice #

Copies a range into a new vector

method : public : Slice(lo:Int, hi:Int) ~ Vector<H>

Parameters

NameTypeDescription
loIntfirst index (inclusive, clamped to 0)
hiIntlast index (exclusive, clamped to Size())

Return

TypeDescription
Vector<H>new vector holding the range, empty if the range is empty

Example

v := Collection.Vector->New()<String>;
v->AddBack("a"); v->AddBack("b"); v->AddBack("c");
v->Slice(1, 3)->Size()->PrintLine(); # 2

Sort #

Sorts the values in place with a comparator. The sort is stable: values the comparator calls equal keep their order.

method : public : Sort(compare:(H,H)~Int) ~ Nil

Parameters

NameTypeDescription
compare(H,H)~Intcomparator: negative if the first value goes first, 0 if equal, positive if the second goes first

Example

v := Collection.Vector->New()<String>;
v->AddBack("pear"); v->AddBack("fig"); v->AddBack("banana");
v->Sort(\(a, b) => a->Size() - b->Size());
v->Get(0)->PrintLine(); # fig

Swap #

Swap two values in the vector

method : public : Swap(a:Int, b:Int) ~ Bool

Parameters

NameTypeDescription
aIntfirst value
bIntsecond value

Return

TypeDescription
Booltrue if values were swapped

Example

v := Collection.Vector->New()<String>;
v->AddBack("a"); v->AddBack("b");
v->Swap(0, 1)->PrintLine(); # true
v->Get(0)->PrintLine(); # b

ToArray #

Converts the vector into an object array

method : public : ToArray() ~ H[]

Return

TypeDescription
H[]object array

Example

v := Collection.Vector->New()<String>;
v->AddBack("a"); v->AddBack("b");
arr := v->ToArray();
arr[0]->PrintLine(); # a

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

v := Collection.Vector->New()<String>;
v->AddBack("a"); v->AddBack("b");
v->ToString()->PrintLine(); # [a,b]

Zip # function

Zip two vectors together

function : Zip() ~ Vector<Collection.Tuple.Pair<H,H>>

Parameters

NameTypeDescription

Return

TypeDescription
Vector<CollectionTuplePair<H,H>>list of pairs

Example

a := Collection.Vector->New()<String>;
a->AddBack("x"); a->AddBack("y");
b := Collection.Vector->New()<String>;
b->AddBack("1"); b->AddBack("2");
zipped := Collection.Vector->Zip(a, b)<String>;
zipped->Get(0)->GetFirst()->PrintLine(); # x

Zip # function

Zip three vectors together

function : Zip() ~ Vector<Collection.Tuple.Triplet<H,H,H>>

Parameters

NameTypeDescription

Return

TypeDescription
Vector<CollectionTupleTriplet<H,H,H>>list of triplets

Example

a := Collection.Vector->New()<String>;
a->AddBack("x");
b := Collection.Vector->New()<String>;
b->AddBack("y");
c := Collection.Vector->New()<String>;
c->AddBack("z");
zipped := Collection.Vector->Zip(a, b, c)<String>;
zipped->Size()->PrintLine(); # 1

Zip # function

Zip four vectors together

function : Zip() ~ Vector<Collection.Tuple.Quartet<H,H,H,H>>

Parameters

NameTypeDescription

Return

TypeDescription
Vector<CollectionTupleQuartet<H,H,H,H>>list of quartets

Example

a := Collection.Vector->New()<String>;
a->AddBack("p");
b := Collection.Vector->New()<String>;
b->AddBack("q");
c := Collection.Vector->New()<String>;
c->AddBack("r");
d := Collection.Vector->New()<String>;
d->AddBack("s");
zipped := Collection.Vector->Zip(a, b, c, d)<String>;
zipped->Size()->PrintLine(); # 1