A queue holds elements until they are read. The order in which elements are read is determined by the implementation of the queue.

interface Queue<E> {
    add(element: E): void;
    clear(): void;
    forEach(fn: (element: E) => unknown): void;
    isEmpty(): boolean;
    length(): number;
    peek(): undefined | E;
    read(): undefined | E;
}

Type Parameters

  • E

Implemented by

Methods

  • Adds an element to the queue.

    Parameters

    • element: E

      the element to add

    Returns void

  • Clears the queue, removing all elements.

    Returns void

  • Calls the given function for each element in the queue.

    Parameters

    • fn: (element: E) => unknown

      the function to call

    Returns void

  • Whether the queue is empty.

    Returns boolean

    true if the queue is empty, false otherwise

  • Number of elements in the queue.

    Returns number

    the number of elements in the queue

  • Returns the next element in the queue without removing it.

    Returns undefined | E

    the next element in the queue, or undefined if the queue is empty

  • Removes and returns the next element in the queue.

    Returns undefined | E

    the next element in the queue, or undefined if the queue is empty