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