Stacks
A stack object, stack
, is a LIFO (last-in-first-out) container type.
-
$stack() -> stack
-
Creates a new
stack
object.
Methods
-
:clear()
-
Removes all items from the stack.
-
:count() -> i64
-
Returns the number of items in the stack.
-
:is_empty() -> bool
-
Returns
true
if the stack is empty. -
:peek() -> any
-
Returns the item on top of the stack without removing it. Returns an
err
if the stack is empty. -
:pop() -> any
-
Removes and returns the item on top of the stack. Returns an
err
if the stack is empty. -
:push(item: any)
-
Pushes an item onto the stack.