datastructures v0.2.6 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

Pop a value from the stack

Push a value in the stack

Reverse the stack

Get the size of the stack

Convert the stack to a list

Types

t()
t
v()
v() :: any

Functions

clear()
empty?(simple)
empty?(t) :: boolean

Check if the stack is empty.

foldl(simple, acc, fun)
foldl(t, any, (v, any -> any)) :: any

Fold the stack from the left.

foldr(simple, acc, fun)
foldr(t, any, (v, any -> any)) :: any

Fold the stack from the right.

member?(simple, value)
member?(t, v) :: boolean

Check if the value is present in the stack.

new()
new() :: t

Creates an empty stack.

new(enum)
new(Enum.t) :: t

Creates a new stack from the given enumerable.

Examples

iex> T.new(1 .. 4)
#Stack<[1,2,3,4]>
peek(simple)
peek(t) :: v

Peek the element that would be popped.

Examples

iex> T.new |> Stack.push(42) |> Stack.peek
42
iex> T.new |> Stack.peek(:empty)
:empty
pop(simple)
pop(t) :: {v, t}

Pop a value from the stack.

Examples

iex> T.new |> Stack.push(42) |> Stack.push(23) |> Stack.pop
{23,#Stack<[42]>}
iex> T.new |> Stack.pop(:empty)
{:empty,#Stack<[]>}
push(simple, value)
push(t, v) :: t

Push a value in the stack.

Examples

iex> T.new |> Stack.push(42) |> Stack.push(23) |> Stack.push(1337)
#Stack<[1337,23,42]>
reverse(simple)
reverse(t) :: t

Reverse the stack.

Examples

iex> T.new(1 .. 4) |> Stack.reverse
#Stack<[4,3,2,1]>
size(simple)
size(t) :: non_neg_integer

Get the size of the stack.

to_list(simple)
to_list(t) :: [v]

Convert the stack to a list.