stella v0.6.0 Stack

Documentation for Stack data structure

Link to this section Summary

Functions

Checks if stack is empty

Creates new, empty stack

Deletes the top element of the stack

Adds a new element to the top of the stack

Link to this section Functions

Link to this function

is_empty(stack)

Specs

is_empty(list()) :: boolean()

Checks if stack is empty

Examples

iex> Stack.is_empty([])
true

iex> Stack.is_empty(["5", 3, 4])
false

Specs

new() :: []

Creates new, empty stack

Examples

iex> Stack.new()
[]

iex> Stack.new() |> Stack.push([1, 2, 3])
[1, 2, 3]

iex> Stack.new() |> Stack.push([1, 2, 3, 4]) |> Stack.pop()
[1, 2, 3]

Specs

pop(list()) :: list()

Deletes the top element of the stack

Examples

iex> Stack.pop([])
[]

iex> Stack.pop([1])
[]
Link to this function

push(stack, element)

Specs

push(list(), list()) :: list()

Adds a new element to the top of the stack

Examples

iex> Stack.push([], 1)
[1]

iex> Stack.push([1, 2], 3)
[1, 2, 3]

iex> Stack.push([1, 2, :xxx], [3, 4, 0.001, 5, "5"])
[1, 2, :xxx, 3, 4, 0.001, 5, "5"]