ixfx
    Preparing search index...

    Interface IQueueImmutable<V>

    Queue (immutable). See also QueueMutable.

    Queues are useful if you want to treat 'older' or 'newer' items differently. Enqueing adds items at the back of the queue, while dequeing removes items from the front (ie. the oldest).

    let q = queue();           // Create
    q = q.enqueue(`a`, `b`); // Add two strings
    const front = q.peek; // `a` is at the front of queue (oldest)
    q = q.dequeue(); // q now just consists of `b`
    const q = queue({capacity: 5, discardPolicy: `newer`});
    
    interface IQueueImmutable<V> {
        get isEmpty(): boolean;
        get isFull(): boolean;
        get length(): number;
        get peek(): undefined | V;
        dequeue(): IQueueImmutable<V>;
        enqueue(...toAdd: readonly V[]): IQueueImmutable<V>;
        forEach(fn: (v: V) => void): void;
        forEachFromFront(fn: (v: V) => void): void;
        toArray(): V[];
    }

    Type Parameters

    • V

    Implemented by

    Accessors

    • get isEmpty(): boolean

      Returns true if queue is empty

      Returns boolean

    • get isFull(): boolean

      Is queue full? Returns false if no capacity has been set

      Returns boolean

    • get length(): number

      Number of items in queue

      Returns number

    • get peek(): undefined | V

      Returns front of queue (oldest item), or undefined if queue is empty

      Returns undefined | V

    Methods

    • Enumerates queue from back-to-front

      Parameters

      • fn: (v: V) => void

      Returns void

    • Enumerates queue from front-to-back

      Parameters

      • fn: (v: V) => void

      Returns void

    • Returns a copy of data in queue as an array

      Returns V[]