Pyro

A dynamically-typed, garbage-collected scripting language.

Version 0.19.2

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;
}

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 true if the queue contains an item equal to value, otherwise false.

:count() -> i64

Returns the number of items in the queue.

:dequeue() -> any

Removes and returns the next item from the queue. Returns an err if the queue is empty.

:enqueue(item: any)

Adds a new item to the queue.

:is_empty() -> bool

Returns true if the queue is empty.

:peek() -> any

Returns the next item from the queue without removing it. Returns an err if the queue is empty.

:values() -> iter

Returns an iterator over the queue's values.