Creates a FIFO queue.
@eryx/queue Module
Queue data structures.
This module provides three small queue-shaped containers:
Queuefor ordinary FIFO usageDequefor pushing/popping at both endsPriorityQueuefor heap-backed min/max priority scheduling
PriorityQueue is implemented as a proper class-style heap queue rather
than as raw heap-list helpers. Linear-time heapify constructors are
provided for priorities, plain items with a priority extractor, and
explicit (item, priority) entries.
Summary
Functions
API Reference
Functions
Queue.new
Parameters
Optional initial values in dequeue order.
Returns
Queue
Queue.from
Builds a FIFO queue from an array.
Parameters
Initial values in dequeue order.
Returns
Queue
Queue:enqueue
Parameters
Value to append at the back.
Returns
Queue
Queue:dequeue
Removes and returns the front item.
Errors when the queue is empty.
Returns
T The removed item.
Queue:peek
Returns the front item without removing it.
Errors when the queue is empty.
Returns
T The next item.
Queue:isEmpty
Returns
boolean true when the queue has no items.
Queue:clear
Removes all items from the queue.
Queue:toArray
Returns
{ T } A shallow array snapshot in dequeue order.
Queue.__iter
Returns the generalized-iteration triple for front-to-back traversal.
Returns
generator, state, index Triple consumed by Luau's for ... in protocol.
Deque.new
Creates a double-ended queue.
Parameters
Optional initial values from front to back.
Returns
Deque
Deque.from
Builds a deque from an array.
Parameters
Initial values from front to back.
Returns
Deque
Deque:pushFront
Parameters
Value to prepend at the front.
Returns
Deque
Deque:pushBack
Parameters
Value to append at the back.
Returns
Deque
Deque:popFront
Removes and returns the front item.
Errors when the deque is empty.
Returns
T The removed item.
Deque:popBack
Removes and returns the back item.
Errors when the deque is empty.
Returns
T The removed item.
Deque:peekFront
Returns the front item without removing it.
Errors when the deque is empty.
Returns
T The next front item.
Deque:peekBack
Returns the back item without removing it.
Errors when the deque is empty.
Returns
T The next back item.
Deque:isEmpty
Returns
boolean true when the deque has no items.
Deque:clear
Removes all items from the deque.
Deque:toArray
Returns
{ T } A shallow array snapshot from front to back.
Deque.__iter
Returns the generalized-iteration triple for front-to-back traversal.
Returns
generator, state, index Triple consumed by Luau's for ... in protocol.
PriorityQueue.new
Creates a heap-backed priority queue.
By default this behaves as a min-priority queue. Callers may either:
- push
(item, priority)pairs directly, or - configure a default priority extractor for future
push(item)calls
Parameters
Optional ordering, comparison, stability, and default priority extraction.
Returns
PriorityQueue<T, P> A new empty priority queue.
PriorityQueue.fromPriorities
Builds a priority queue from an array of raw priority values in linear time.
Parameters
Initial priorities to heapify.
Optional ordering, comparison, and stability hooks.
Returns
PriorityQueue<P, P> A heapified queue.
PriorityQueue.from
Builds a priority queue from an array of items in linear time.
Parameters
Initial items to heapify.
Extracts a priority from each item.
Optional ordering, comparison, and stability hooks.
Returns
PriorityQueue<T, P> A heapified queue.
PriorityQueue.fromEntries
Builds a priority queue from explicit (item, priority) entries in
linear time.
Parameters
Initial entries to heapify.
Optional ordering, comparison, and stability hooks.
Returns
PriorityQueue<T, P> A heapified queue.
PriorityQueue:push
Parameters
Value to enqueue.
Optional explicit priority override for this item.
Returns
PriorityQueue<T, P> Enables chaining.
PriorityQueue:pop
Removes and returns the next item by priority.
Errors when the queue is empty.
Returns
T The removed item.
PriorityQueue:popEntry
Removes and returns the next (item, priority) entry.
Errors when the queue is empty.
Returns
PriorityQueueEntry<T, P> The removed entry.
PriorityQueue:peek
Returns the next item by priority without removing it.
Errors when the queue is empty.
Returns
T The next item.
PriorityQueue:peekEntry
Returns the next (item, priority) entry without removing it.
Errors when the queue is empty.
Returns
PriorityQueueEntry<T, P> The next entry.
PriorityQueue:pushPop
Pushes a new item, then pops and returns the next item by priority.
When the queue is empty, this returns the pushed item.
Parameters
Value to enqueue.
Optional explicit priority override for this item.
Returns
T The item that was removed.
PriorityQueue:replace
Pops the current next item by priority, then inserts the replacement.
This is the queue-shaped equivalent of Python's heapreplace.
Errors when the queue is empty.
Parameters
Replacement value to enqueue.
Optional explicit priority override for the replacement.
Returns
T The item that was removed.
PriorityQueue:isEmpty
Returns
boolean true when the priority queue has no items.
PriorityQueue:clear
Removes all items from the priority queue.
PriorityQueue:toHeapArray
Returns a shallow snapshot of items in internal heap layout.
This result is not priority-sorted; it reflects heap structure only.
Returns
{ T } A shallow item snapshot in heap order.
PriorityQueue:toHeapEntries
Returns a shallow snapshot of entries in internal heap layout.
This result is not priority-sorted; it reflects heap structure only. Hidden stability bookkeeping such as insertion sequence is not exposed.
Returns
{ PriorityQueueEntry<T, P> } A shallow entry snapshot in heap order.
PriorityQueue:toSortedArray
Returns items in pop order without mutating the original queue.
Returns
{ T } A shallow item snapshot in priority-sorted order.
PriorityQueue:toSortedEntries
Returns entries in pop order without mutating the original queue.
Hidden stability bookkeeping such as insertion sequence is not exposed.
Returns
{ PriorityQueueEntry<T, P> } A shallow entry snapshot in priority-sorted order.
PriorityQueue:clone
Returns a shallow copy of this priority queue.
When stability is enabled, cloned queues preserve insertion-order tiebreak behavior.
Returns
PriorityQueue<T, P> A shallow copy of this priority queue.