@ac-essentials/misc-util
    Preparing search index...

    Interface IStack<T>

    Interface representing a stack data type

    A stack is a collection that follows the Last In First Out (LIFO) principle, where the last item added to the stack is the first one to be removed.

    interface IStack<T = unknown> {
        capacity: number;
        "[asyncIterator]"(): AsyncIterator<T, any, any>;
        "[iterator]"(): Iterator<Promisable<T>, any, any>;
        clear(): Promisable<void>;
        concat(...items: T[]): MaybeAsyncIterableIterator<T>;
        count(): Promisable<number>;
        pop(): Promisable<T | undefined>;
        push(...items: T[]): Promisable<void>;
        remove(
            condition: Predicate<[T]>,
        ): Promisable<MaybeAsyncIterableIterator<T>>;
        removeFirst(condition: Predicate<[T]>): Promisable<boolean>;
        replace(
            condition: Predicate<[T]>,
            newItemFactory: Callable<[T], T>,
        ): Promisable<MaybeAsyncIterableIterator<T>>;
        replaceFirst(condition: Predicate<[T]>, newItem: T): Promisable<boolean>;
        top(): Promisable<T | undefined>;
        waitPush(
            items: Iterable<T>,
            signal?: AbortSignal | null,
        ): PromiseLike<void>;
    }

    Type Parameters

    • T = unknown

      The type of elements in the stack.

    Hierarchy (View Summary)

    Implemented by

    Index

    Properties

    capacity: number

    The maximum number of elements the collection can hold. If the collection is unbounded, this will be Infinity.

    Methods

    • Returns AsyncIterator<T, any, any>

    • Returns Iterator<Promisable<T>, any, any>

    • Removes and returns the item at the top of the stack.

      Returns Promisable<T | undefined>

      The item at the top of the stack, or undefined if the stack is empty.

    • Adds one or more items to the top of the stack.

      The items are added in the order they are provided. The last item in the argument list will be the first one to be popped.

      Parameters

      • ...items: T[]

        The items to add to the stack.

      Returns Promisable<void>

      If the operation would exceed the stack's capacity.

    • Replaces the first occurence of the item matching the given predicate in the collection with a new item.

      Parameters

      • condition: Predicate<[T]>

        A predicate function to identify the item to replace.

      • newItem: T

        The new item to insert.

      Returns Promisable<boolean>

      true if the item was found and replaced, false otherwise.

    • Returns the item at the top of the stack without removing it.

      Returns Promisable<T | undefined>

      The item at the top of the stack, or undefined if the stack is empty.

    • Same as push, but waits for capacity if the operation would exceed it.

      Parameters

      • items: Iterable<T>
      • Optionalsignal: AbortSignal | null

        Optional abort signal to cancel the operation.

      Returns PromiseLike<void>

      IStack.push