Interface ImmutableStack<T>
- Type Parameters:
T
- type of elements
- All Superinterfaces:
Iterable<T>
- All Known Implementing Classes:
ImmutableStackImpl
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
Methods inherited from interface java.lang.Iterable
forEach, iterator, spliterator
-
Method Details
-
push
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
ImmutableStack<T> 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
-