v2026.5.3
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.

CompareList

List of comparable generics

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

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

   # find value
   list->Has(66.6)->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.CompareList->New()<IntRef>;
list->AddBack(IntRef->New(5));
list->AddBack(IntRef->New(10));
list->Back()->PrintLine(); # 10

AddFront # native

Adds a value to the front

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

Parameters

NameTypeDescription
valueHvalue to prepend

Example

list := Collection.CompareList->New()<IntRef>;
list->AddBack(IntRef->New(2));
list->AddFront(IntRef->New(1));
list->Front()->PrintLine(); # 1

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.CompareList->New()<IntRef>;
list->AddBack(IntRef->New(10));
list->AddBack(IntRef->New(20));
list->Back()->PrintLine(); # 20

BackwardIterator #

Instance of a backward iterator

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

Return

TypeDescription
CompareBackwardIterator<H>Backward iterator

Example

list := Collection.CompareList->New()<IntRef>;
list->AddBack(IntRef->New(1));
list->AddBack(IntRef->New(2));
it := list->BackwardIterator()<IntRef>;
while(it->More()) {
   it->Get()->PrintLine();
   it->Next();
};

Empty #

Clears the list

method : public : Empty() ~ Nil

Example

list := Collection.CompareList->New()<IntRef>;
list->AddBack(IntRef->New(1));
list->Empty();
list->IsEmpty()->PrintLine(); # true

Filter #

Uses the given function to filter out values

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

Example

list := Collection.CompareList->New()<IntRef>;
list->AddBack(IntRef->New(1));
list->AddBack(IntRef->New(2));
list->AddBack(IntRef->New(3));
evens := list->Filter(\(v : IntRef) ~ Bool { return v->Get() % 2 = 0; });
evens->Size()->PrintLine(); # 1

Find #

Finds a value in the list and sets the pointer

method : public : Find(value:H) ~ H

Parameters

NameTypeDescription
valueHvalue to search for

Return

TypeDescription
Hvalue that's found

Example

list := Collection.CompareList->New()<IntRef>;
list->AddBack(IntRef->New(1));
list->AddBack(IntRef->New(2));
found := list->Find(IntRef->New(2));
found->PrintLine(); # 2

Forward #

Moves the pointer to the end of the list

method : public : Forward() ~ Nil

Example

list := Collection.CompareList->New()<IntRef>;
list->AddBack(IntRef->New(1));
list->AddBack(IntRef->New(2));
list->Forward();
list->Get()->PrintLine(); # 2

ForwardIterator #

Instance of a forward iterator

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

Return

TypeDescription
CompareForwardIterator<H>forward iterator

Example

list := Collection.CompareList->New()<IntRef>;
list->AddBack(IntRef->New(1));
list->AddBack(IntRef->New(2));
it := list->ForwardIterator()<IntRef>;
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.CompareList->New()<IntRef>;
list->AddBack(IntRef->New(10));
list->AddBack(IntRef->New(20));
list->Front()->PrintLine(); # 10

Get #

Gets the value that's currently pointed to

method : public : Get() ~ H

Return

TypeDescription
Hvalue value

Example

list := Collection.CompareList->New()<IntRef>;
list->AddBack(IntRef->New(42));
list->Rewind();
list->Get()->PrintLine(); # 42

Has #

Searches for a value

method : public : Has(value:H) ~ Bool

Parameters

NameTypeDescription
valueHvalue to check for

Return

TypeDescription
Booltrue if value is found, false otherwise

Example

list := Collection.CompareList->New()<IntRef>;
list->AddBack(IntRef->New(5));
list->AddBack(IntRef->New(10));
list->Has(IntRef->New(5))->PrintLine();  # true
list->Has(IntRef->New(99))->PrintLine(); # false

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.CompareList->New()<IntRef>;
list->AddBack(IntRef->New(1));
list->AddBack(IntRef->New(3));
list->Rewind();
list->Insert(IntRef->New(2));
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.CompareList->New()<IntRef>;
list->AddBack(IntRef->New(1));
list->AddBack(IntRef->New(2));
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.CompareList->New()<IntRef>;
list->IsEmpty()->PrintLine(); # true
list->AddBack(IntRef->New(1));
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.CompareList->New()<IntRef>;
list->AddBack(IntRef->New(1));
list->AddBack(IntRef->New(2));
list->Rewind();
list->IsFront()->PrintLine(); # true
list->Next();
list->IsFront()->PrintLine(); # false

Map #

Maps the given function to each value in the list

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

Parameters

NameTypeDescription
f(H)~Hfunction to apply

Return

TypeDescription
CompareList<H>newly calculated list

Example

list := Collection.CompareList->New()<IntRef>;
list->AddBack(IntRef->New(3));
list->AddBack(IntRef->New(4));
doubled := list->Map(\(v : IntRef) ~ IntRef { return IntRef->New(v->Get() * 2); });
doubled->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.CompareList->New()<IntRef>;
list->AddBack(IntRef->New(1));
list->Rewind();
while(list->More()) {
   list->Get()->PrintLine();
   list->Next();
};

New # constructor

Default constructor

New()

Example

list := Collection.CompareList->New()<IntRef>;
list->AddBack(IntRef->New(1));
list->AddBack(IntRef->New(2));
list->Size()->PrintLine(); # 2

Next #

Advances the pointer

method : public : Next() ~ Nil

Example

list := Collection.CompareList->New()<IntRef>;
list->AddBack(IntRef->New(1));
list->AddBack(IntRef->New(2));
list->Rewind();
list->Next();
list->Get()->PrintLine(); # 2

Previous #

Retreats the pointer

method : public : Previous() ~ Nil

Example

list := Collection.CompareList->New()<IntRef>;
list->AddBack(IntRef->New(1));
list->AddBack(IntRef->New(2));
list->Forward();
list->Previous();
list->Get()->PrintLine(); # 1

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.CompareList->New()<IntRef>;
list->AddBack(IntRef->New(1));
list->AddBack(IntRef->New(2));
list->AddBack(IntRef->New(3));
sum := list->Reduce(IntRef->New(0), \(a : IntRef, v : IntRef) ~ IntRef { return IntRef->New(a->Get() + v->Get()); });
sum->PrintLine(); # 6

Remove # native

Removes the element at the pointer position

method : public : native : Remove() ~ Nil

Example

list := Collection.CompareList->New()<IntRef>;
list->AddBack(IntRef->New(1));
list->AddBack(IntRef->New(2));
list->Rewind();
list->Remove();
list->Size()->PrintLine(); # 1

Remove # native

Removes the element at the pointer position

method : public : native : Remove(node:CompareListNode<H>) ~ Nil

Parameters

NameTypeDescription
nodeCompareListNode<H>node

RemoveBack #

Removes the last value from the list

method : public : RemoveBack() ~ Nil

Example

list := Collection.CompareList->New()<IntRef>;
list->AddBack(IntRef->New(1));
list->AddBack(IntRef->New(2));
list->RemoveBack();
list->Back()->PrintLine(); # 1

RemoveFront #

Removes the first value from the list

method : public : RemoveFront() ~ Nil

Example

list := Collection.CompareList->New()<IntRef>;
list->AddBack(IntRef->New(1));
list->AddBack(IntRef->New(2));
list->RemoveFront();
list->Front()->PrintLine(); # 2

Rest #

List of all but first element

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

Return

TypeDescription
CompareList<H>all but first element

Example

list := Collection.CompareList->New()<IntRef>;
list->AddBack(IntRef->New(1));
list->AddBack(IntRef->New(2));
list->AddBack(IntRef->New(3));
rest := list->Rest();
rest->Size()->PrintLine(); # 2

Rewind #

Moves the pointer to the start of the list

method : public : Rewind() ~ Nil

Example

list := Collection.CompareList->New()<IntRef>;
list->AddBack(IntRef->New(1));
list->AddBack(IntRef->New(2));
list->Forward();
list->Rewind();
list->Get()->PrintLine(); # 1

Size #

Size of list

method : public : Size() ~ Int

Return

TypeDescription
Intsize of list

Example

list := Collection.CompareList->New()<IntRef>;
list->AddBack(IntRef->New(1));
list->AddBack(IntRef->New(2));
list->Size()->PrintLine(); # 2

ToArray #

Converts the list into an object array

method : public : ToArray() ~ H[]

Return

TypeDescription
H[]object array

Example

list := Collection.CompareList->New()<IntRef>;
list->AddBack(IntRef->New(10));
list->AddBack(IntRef->New(20));
arr := list->ToArray();
arr[0]->PrintLine(); # 10

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.CompareList->New()<IntRef>;
list->AddBack(IntRef->New(1));
list->AddBack(IntRef->New(2));
list->ToString()->PrintLine(); # [1,2]