Stacks
A stack object, stack, is a LIFO (last-in-first-out) container type.
-
$stack() -> stack -
Creates a new stack.
Iterating
Stacks are iterable, e.g.
var stack = $stack(); stack:push("foo"); stack:push("bar"); for item in stack { echo item; }
The :values() method returns an iterator wrapper over the stack's values.
Containment
You can check if a stack contains an item using the in operator, e.g.
var stack = $stack(); stack:push("foo"); stack:push("bar"); assert "foo" in stack;
This is equivalent to calling the stack's :contains() method.
Methods
-
:clear() -
Removes all items from the stack.
-
:contains(value: any) -> bool -
Returns
trueif the stack contains an item equal tovalue, otherwisefalse. -
:count() -> i64 -
Returns the number of items in the stack.
-
:is_empty() -> bool -
Returns
trueif the stack is empty. -
:iter() -> iter -
Returns an
iterobject wrapping the stack. -
:peek() -> any -
Returns the item on top of the stack without removing it. Returns an
errif the stack is empty. -
:pop() -> any -
Removes and returns the item on top of the stack. Returns an
errif the stack is empty. -
:push(item: any) -
Pushes an item onto the stack.
-
:values() -> iter -
Returns an iterator wrapper over the stack's values.