Stack (stella v0.7.0)

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)

@spec is_empty(list()) :: boolean()

Checks if stack is empty

examples

Examples

iex> Stack.is_empty([])
true

iex> Stack.is_empty(["5", 3, 4])
false
@spec new() :: []

Creates new, empty stack

examples

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]
@spec pop(list()) :: list()

Deletes the top element of the stack

examples

Examples

iex> Stack.pop([])
[]

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

push(stack, element)

@spec push(list(), list()) :: list()

Adds a new element to the top of the stack

examples

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"]