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

t
v :: any

Functions

clear()
empty?(simple)

Specs

empty?(t) :: boolean

Check if the stack is empty.

foldl(simple, acc, fun)

Specs

foldl(t, any, (v, any -> any)) :: any

Fold the stack from the left.

foldr(simple, acc, fun)

Specs

foldr(t, any, (v, any -> any)) :: any

Fold the stack from the right.

member?(simple, value)

Specs

member?(t, v) :: boolean

Check if the value is present in the stack.

new()

Specs

new :: t

Creates an empty stack.

new(enum)

Specs

new(Enum.t) :: t

Creates a new stack from the given enumerable.

Examples

iex> Data.Stack.Simple.new(1 .. 4)
#Stack<[1,2,3,4]>
peek(stack, default \\ nil)

Specs

peek(t, v) :: v

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!(stack)

Specs

peek!(t) :: v | no_return

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(stack, default \\ nil)

Specs

pop(t, v) :: {v, t}

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!(self)

Specs

pop!(t) :: {v, t} | no_return

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(simple, value)

Specs

push(t, v) :: t

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(simple)

Specs

reverse(t) :: t

Reverse the stack.

Examples

iex> Data.Stack.Simple.new(1 .. 4) |> Stack.reverse
#Stack<[4,3,2,1]>
size(simple)

Specs

size(t) :: non_neg_integer

Get the size of the stack.

to_list(simple)

Specs

to_list(t) :: [v]

Convert the stack to a list.