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.

Stack

Growable stack of generics (LIFO)

Example

stack := Collection.Stack->New()<IntRef>;
stack->Push(1);
stack->Push(2);
stack->Push(3);
stack->Pop()->PrintLine();  # prints 3
stack->Top()->PrintLine();  # prints 2
stack->Size()->PrintLine(); # prints 2

Operations

Empty #

Clears the stack

method : public : Empty() ~ Nil

Example

stack := Collection.Stack->New()<IntRef>;
stack->Push(IntRef->New(5));
stack->Empty();
stack->IsEmpty()->PrintLine(); # true

IsEmpty #

Checks to see if the stack is empty

method : public : IsEmpty() ~ Bool

Return

TypeDescription
Booltrue if empty, false otherwise

Example

stack := Collection.Stack->New()<IntRef>;
stack->IsEmpty()->PrintLine(); # true
stack->Push(IntRef->New(1));
stack->IsEmpty()->PrintLine(); # false

New # constructor

Default constructor

New()

Example

stack := Collection.Stack->New()<String>;
stack->Push("a");
stack->Push("b");
stack->Pop()->PrintLine(); # b

Pop # native

Pops values from the stack

method : public : native : Pop(n:Int) ~ H

Parameters

NameTypeDescription
nIntnumber of items to pop

Return

TypeDescription
Hpopped valued, Nil if stack is empty

Example

stack := Collection.Stack->New()<IntRef>;
stack->Push(IntRef->New(1));
stack->Push(IntRef->New(2));
stack->Push(IntRef->New(3));
stack->Pop(2)->PrintLine(); # 2 (value after skipping 2 items)

Pop #

Pops a value from the stack

method : public : Pop() ~ H

Return

TypeDescription
Hpopped valued, Nil if stack is empty

Example

stack := Collection.Stack->New()<IntRef>;
stack->Push(IntRef->New(7));
stack->Push(IntRef->New(8));
stack->Pop()->PrintLine(); # 8
stack->Size()->PrintLine(); # 1

Push #

Pushes a value onto the stack

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

Parameters

NameTypeDescription
valueHto push

Example

stack := Collection.Stack->New()<IntRef>;
stack->Push(IntRef->New(10));
stack->Push(IntRef->New(20));
stack->Top()->PrintLine(); # 20

Size #

Size of stack

method : public : Size() ~ Int

Return

TypeDescription
Intsize of stack

Example

stack := Collection.Stack->New()<IntRef>;
stack->Push(IntRef->New(1));
stack->Push(IntRef->New(2));
stack->Size()->PrintLine(); # 2

ToArray # native

Converts the stack into an object array

method : public : native : ToArray() ~ H[]

Return

TypeDescription
H[]object array

Example

stack := Collection.Stack->New()<String>;
stack->Push("x");
stack->Push("y");
arr := stack->ToArray();
arr[0]->PrintLine(); # y (top element)

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

stack := Collection.Stack->New()<IntRef>;
stack->Push(IntRef->New(1));
stack->Push(IntRef->New(2));
stack->ToString()->PrintLine(); # [2,1]

Top #

Check the top of the stack

method : public : Top() ~ H

Return

TypeDescription
Hvalue on the top of stack, Nil if stack is empty

Example

stack := Collection.Stack->New()<IntRef>;
stack->Push(IntRef->New(42));
stack->Top()->PrintLine(); # 42
stack->Size()->PrintLine(); # 1 (Top does not remove)