v2026.6.4
All Bundles
Bundle Generic collections library: Vector (dynamic array), Map (hash map), Set, MultiMap, Stack, Queue, and Pair. Provides typed iteration, sorting, filtering, and functional operations (Reduce, Any, All). Compile with -lib gen_collect.

List

Generic list

Example

function : Example() ~ Nil {
   # insert elements
   list := Collection.List->New()<FloatRef>;
   list->AddBack(33.3);
   list->AddFront(66.6);
   list->AddBack(99.9);

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

   # get first and last item
   list->Front()->PrintLine();
   list->Back()->PrintLine();

   # iterate
   while(list->More()) {
      list->Get()->PrintLine();
      list->Next();
   };

   # iterate backward   
   backwards := list->BackwardIterator()<FloatRef>;
   while(backwards->More()) {
      backwards->Get()->PrintLine();
      backwards->Next();
   };
}

Operations

AddBack # native

Adds a value to the end

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

Parameters

NameTypeDescription
valueHvalue to append

Example

list := Collection.List->New()<String>;
list->AddBack("first");
list->AddBack("second");
list->Back()->PrintLine(); # second

AddFront # native

Adds a value to the front

method : public : native : AddFront(value:H) ~ Nil

Parameters

NameTypeDescription
valueHvalue to prepend

Example

list := Collection.List->New()<String>;
list->AddBack("second");
list->AddFront("first");
list->Front()->PrintLine(); # first

Back #

Returns the last element in the list

method : public : Back() ~ H

Return

TypeDescription
Hlast element in the list, Nil if the list is empty

Example

list := Collection.List->New()<String>;
list->AddBack("first");
list->AddBack("last");
list->Back()->PrintLine(); # last

BackwardIterator #

Instance of a backward iterator

method : public : BackwardIterator() ~ BackwardIterator<H>

Return

TypeDescription
BackwardIterator<H>Backward iterator

Example

list := Collection.List->New()<String>;
list->AddBack("x");
list->AddBack("y");
it := list->BackwardIterator()<String>;
while(it->More()) {
   it->Get()->PrintLine();
   it->Next();
};

Each #

Function called for each element

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

Parameters

NameTypeDescription
f(H)~Nilfunction called

Example

list := Collection.List->New()<String>;
list->AddBack("a");
list->AddBack("b");
list->Each(\(s : String) ~ Nil { s->PrintLine(); });

Empty #

Clears the list

method : public : Empty() ~ Nil

Example

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

Filter #

Uses the given function to filter out values

method : public : Filter(f:(H)~Bool) ~ List<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
List<H>filtered list

Example

list := Collection.List->New()<String>;
list->AddBack("apple");
list->AddBack("banana");
list->AddBack("apricot");
filtered := list->Filter(\(s : String) ~ Bool { return s->StartsWith("a"); });
filtered->Size()->PrintLine(); # 2

Forward #

Moves the pointer to the end of the list

method : public : Forward() ~ Nil

Example

list := Collection.List->New()<String>;
list->AddBack("a");
list->AddBack("b");
list->Forward();
list->Get()->PrintLine(); # b

ForwardIterator #

Instance of a forward iterator

method : public : ForwardIterator() ~ ForwardIterator<H>

Return

TypeDescription
ForwardIterator<H>forward iterator

Example

list := Collection.List->New()<String>;
list->AddBack("x");
list->AddBack("y");
it := list->ForwardIterator()<String>;
while(it->More()) {
   it->Get()->PrintLine();
   it->Next();
};

Front #

Returns the first element in the list

method : public : Front() ~ H

Return

TypeDescription
Hfirst element in the list, Nil if the list is empty

Example

list := Collection.List->New()<String>;
list->AddBack("first");
list->AddBack("last");
list->Front()->PrintLine(); # first

Get #

Gets the value that's currently pointed to

method : public : Get() ~ H

Return

TypeDescription
Hvalue value

Example

list := Collection.List->New()<String>;
list->AddBack("hello");
list->Rewind();
list->Get()->PrintLine(); # hello

Insert # native

Inserts a value into the list based upon the pointer location

method : public : native : Insert(value:H) ~ Bool

Parameters

NameTypeDescription
valueHvalue to insert

Example

list := Collection.List->New()<String>;
list->AddBack("a");
list->AddBack("c");
list->Rewind();
list->Insert("b");
list->Size()->PrintLine(); # 3

IsBack #

Checks to see if the pointer is at the end of the list

method : public : IsBack() ~ Bool

Return

TypeDescription
Booltrue if pointer is at the end of the list, false otherwise

Example

list := Collection.List->New()<String>;
list->AddBack("a");
list->AddBack("b");
list->Forward();
list->IsBack()->PrintLine(); # true

IsEmpty #

Checks to see if the list is empty

method : public : IsEmpty() ~ Bool

Return

TypeDescription
Booltrue if empty, false otherwise

Example

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

IsFront #

Checks to see if the pointer is at the front of the list

method : public : IsFront() ~ Bool

Return

TypeDescription
Booltrue if pointer is at the front of the list, false otherwise

Example

list := Collection.List->New()<String>;
list->AddBack("a");
list->AddBack("b");
list->Rewind();
list->IsFront()->PrintLine(); # true

Limit #

Returns a limited list

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

Parameters

NameTypeDescription
lIntlimit

Return

TypeDescription
List<H>limited list

Example

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

Map #

Maps the given function to each value in the list

method : public : Map(f:(H)~H) ~ List<H>

Parameters

NameTypeDescription
f(H)~Hfunction to apply

Return

TypeDescription
List<H>newly calculated list

Example

list := Collection.List->New()<String>;
list->AddBack("hello");
list->AddBack("world");
upper := list->Map(\(s : String) ~ String { return s->ToUpper(); });
upper->Size()->PrintLine(); # 2

More #

Checks to see the pointer can be advanced

method : public : More() ~ Bool

Return

TypeDescription
Booltrue if pointer can be advanced, false otherwise

Example

list := Collection.List->New()<String>;
list->AddBack("x");
list->Rewind();
while(list->More()) {
   list->Get()->PrintLine();
   list->Next();
};

New # constructor

Default constructor

New()

Example

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

Next #

Advances the pointer

method : public : Next() ~ Nil

Example

list := Collection.List->New()<String>;
list->AddBack("a");
list->AddBack("b");
list->Rewind();
list->Next();
list->Get()->PrintLine(); # b

Previous #

Retreats the pointer

method : public : Previous() ~ Nil

Example

list := Collection.List->New()<String>;
list->AddBack("a");
list->AddBack("b");
list->Forward();
list->Previous();
list->Get()->PrintLine(); # a

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 vector

Example

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

Remove # native

Removes the element at the pointer position

method : public : native : Remove() ~ Nil

RemoveBack #

Removes the last value from the list

method : public : RemoveBack() ~ Nil

Example

list := Collection.List->New()<String>;
list->AddBack("a");
list->AddBack("b");
list->RemoveBack();
list->Back()->PrintLine(); # a

RemoveFront #

Removes the first value from the list

method : public : RemoveFront() ~ Nil

Example

list := Collection.List->New()<String>;
list->AddBack("a");
list->AddBack("b");
list->RemoveFront();
list->Front()->PrintLine(); # b

Rest #

List of all but first element

method : public : Rest() ~ List<H>

Return

TypeDescription
List<H>all but first element

Example

list := Collection.List->New()<String>;
list->AddBack("a");
list->AddBack("b");
list->AddBack("c");
rest := list->Rest();
rest->Size()->PrintLine();   # 2
rest->Front()->PrintLine();  # b

Rewind #

Moves the pointer to the start of the list

method : public : Rewind() ~ Nil

Example

list := Collection.List->New()<String>;
list->AddBack("a");
list->AddBack("b");
list->Forward();
list->Rewind();
list->Get()->PrintLine(); # a

Size #

Size of list

method : public : Size() ~ Int

Return

TypeDescription
Intsize of list

Example

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

ToArray #

Converts the list into an object array

method : public : ToArray() ~ H[]

Return

TypeDescription
H[]object array

Example

list := Collection.List->New()<String>;
list->AddBack("a");
list->AddBack("b");
arr := list->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

list := Collection.List->New()<String>;
list->AddBack("foo");
list->AddBack("bar");
list->ToString()->PrintLine(); # [foo,bar]