yaq v1.0.0 Yaq View Source
Yet Another Queue module for Elixir
Link to this section Summary
Functions
Remove an item from the front of the queue.
Remove an item from the rear of the queue.
Push a new term onto the rear of the queue.
Push a new term onto the front of the queue.
Create a new queue.
Return the front element of the queue. Returns nil
if empty
Returns the rear element of the queue.
Return the number of elements in the queue.
Return the elements of the queue as a list.
Link to this section Types
Specs
t()
Specs
value() :: nil | term()
Link to this section Functions
Specs
Remove an item from the front of the queue.
Examples
iex> {term, q} = Yaq.new(1..3) |> Yaq.dequeue()
iex> term
1
iex> q
#Yaq<length: 2>
Specs
Remove an item from the rear of the queue.
Examples
iex> {term, q} = Yaq.new(1..3) |> Yaq.dequeue_r()
iex> term
3
iex> q
#Yaq<length: 2>
Specs
Push a new term onto the rear of the queue.
Parameters
q
: Current queueterm
: Elixir term to enqueue
Examples
iex> q = Yaq.new()
#Yaq<length: 0>
iex> q = Yaq.enqueue(q, 1)
#Yaq<length: 1>
iex> q = Yaq.enqueue(q, 2)
#Yaq<length: 2>
iex> Yaq.to_list(q)
[1, 2]
Specs
Push a new term onto the front of the queue.
Examples
iex> q = Yaq.new()
#Yaq<length: 0>
iex> q = Yaq.enqueue_r(q, 1)
#Yaq<length: 1>
iex> q = Yaq.enqueue_r(q, 2)
#Yaq<length: 2>
iex> Yaq.to_list(q)
[2, 1]
Specs
new(Enumerable.t()) :: t()
Create a new queue.
Parameters
enum
(optional): initial queue data
Examples
iex> Yaq.new()
#Yaq<length: 0>
iex> Yaq.new(1..10)
#Yaq<length: 10>
Specs
Return the front element of the queue. Returns nil
if empty
Parameters
q
: Current queue
Examples
iex> Yaq.new() |> Yaq.peek()
nil
iex> Yaq.new(1..3) |> Yaq.peek()
1
Specs
Returns the rear element of the queue.
Parameters
q
: Current queue
Examples
iex> Yaq.new() |> Yaq.peek_r()
nil
iex> Yaq.new(1..3) |> Yaq.peek_r()
3
Specs
size(t()) :: non_neg_integer()
Return the number of elements in the queue.
Parameters
q
: Current queue
Examples
iex> Yaq.new() |> Yaq.size()
0
iex> Yaq.new(1..3) |> Yaq.size()
3
Specs
Return the elements of the queue as a list.
Parameters
q
: Current queue
Examples
iex> Yaq.new([1, 2, 3]) |> Yaq.to_list()
[1, 2, 3]