ixfx
    Preparing search index...

    Class StackMutable<V>

    Creates a stack. Mutable. Use StackImmutable for an immutable alternative.

    // Create
    const s = new StackMutable();
    // Add one or more items
    s.push(1, 2, 3, 4);

    // See what's on top
    s.peek; // 4

    // Remove the top-most, and return it
    s.pop(); // 4

    // Now there's a new top-most element
    s.peek; // 3

    Type Parameters

    • V

    Implements

    Constructors

    Properties

    Accessors

    Methods

    Constructors

    Properties

    data: readonly V[]
    opts: StackOpts

    Accessors

    • get isEmpty(): boolean

      True if stack is empty

      Returns boolean

    • get isFull(): boolean

      True if stack is at its capacity. False if not, or if there is no capacity.

      Returns boolean

    • get length(): number

      Number of items in stack

      Returns number

    • get peek(): undefined | V

      Get the item at the top of the stack without removing it (like pop would do)

      Returns undefined | V

      Item at the top of the stack, or undefined if empty.

    Methods

    • Enumerates stack from bottom-to-top

      Parameters

      • fn: (v: V) => void

      Returns void

    • Enumerates stack from top-to-bottom

      Parameters

      • fn: (v: V) => void

      Returns void

    • Remove and return item from the top of the stack, or undefined if empty. If you just want to find out what's at the top, use peek.

      Returns undefined | V

    • Push data onto the stack. If toAdd is empty, nothing happens

      Parameters

      • ...toAdd: readonly V[]

        Data to add

      Returns number

      Length of stack