Interface ImmutableStack<T>

Type Parameters:
T - type of elements
All Superinterfaces:
Iterable<T>
All Known Implementing Classes:
ImmutableStackImpl

public interface ImmutableStack<T> extends Iterable<T>
This stack is considered 'immutable' because no operations are performed in-place at any given element. All 'modifying' operations like push and pop return new stacks.
  • Method Summary

    Modifier and Type
    Method
    Description
    int
    The depth of current stack.
    boolean
    True if stack is empty.
    See the current element.
    pop()
    Returns the tail of the current stack.
    push(T element)
    Creates a new stack out of the element and appends the previous stack to it.

    Methods inherited from interface java.lang.Iterable

    forEach, iterator, spliterator
  • Method Details

    • push

      ImmutableStack<T> push(T element)
      Creates a new stack out of the element and appends the previous stack to it.
      Parameters:
      element - to create a new stack from
      Returns:
      new stack
    • pop

      Returns the tail of the current stack.
      Returns:
      tail of current stack stack
    • peek

      T peek()
      See the current element.
      Returns:
      current element
    • depth

      int depth()
      The depth of current stack.
      Returns:
      depth of current stack
    • isEmpty

      boolean isEmpty()
      True if stack is empty.
      Returns:
      true if stack is empty