datastructures v0.1.1 Data.Stack.Simple
A simple stack.
Summary
Functions
Check if the stack is empty
Fold the stack from the left
Fold the stack from the right
Check if the value is present in the stack
Creates an empty stack
Creates a new stack from the given enumerable
Peek the element that would be popped
Peek the element that should be popped, raising if it's empty
Pop a value from the stack
Pop a value from the stack, raising if it's empty
Push a value in the stack
Reverse the stack
Get the size of the stack
Convert the stack to a list
Types
Functions
Creates a new stack from the given enumerable.
Examples
iex> Data.Stack.Simple.new(1 .. 4)
#Stack<[1,2,3,4]>
Peek the element that would be popped.
Examples
iex> Data.Stack.Simple.new |> Stack.push(42) |> Stack.peek
42
iex> Data.Stack.Simple.new |> Stack.peek(:empty)
:empty
Peek the element that should be popped, raising if it's empty.
Examples
iex> Data.Stack.Simple.new |> Stack.push(42) |> Stack.push(23) |> Stack.peek!
23
iex> Data.Stack.Simple.new |> Stack.peek!
** (Data.Error.Empty) the stack is empty
Pop a value from the stack.
Examples
iex> Data.Stack.Simple.new |> Stack.push(42) |> Stack.push(23) |> Stack.pop
{23,#Stack<[42]>}
iex> Data.Stack.Simple.new |> Stack.pop(:empty)
{:empty,#Stack<[]>}
Pop a value from the stack, raising if it's empty.
Examples
iex> Data.Stack.Simple.new |> Stack.push(42) |> Stack.pop
{42,#Stack<[]>}
iex> Data.Stack.Simple.new |> Stack.pop!
** (Data.Error.Empty) the queue is empty
Push a value in the stack.
Examples
iex> Data.Stack.Simple.new |> Stack.push(42) |> Stack.push(23) |> Stack.push(1337)
#Stack<[1337,23,42]>
Reverse the stack.
Examples
iex> Data.Stack.Simple.new(1 .. 4) |> Stack.reverse
#Stack<[4,3,2,1]>