Returns a stack. Immutable. Use Stacks.mutable for a mutable alternative.

The basic usage is push/pop to add/remove, returning the modified stack. Use the property peek to see what's on top.

// Create
let s = stack();
// Add one or more items
s = s.push(1, 2, 3, 4);
// See what's at the top of the stack
s.peek; // 4

// Remove from the top of the stack, returning
// a new stack without item
s = s.pop();
s.peek; // 3
  • Type Parameters

    • V

    Parameters

    • options: StackOpts = {}

      Options

    • Rest...startingItems: readonly V[]

      List of items to add to stack. Items will be pushed 'left to right', ie array index 0 will be bottom of the stack.

    Returns IStackImmutable<V>