Quex (Quex v1.0.1)
View SourceQuex
Simple queue implementation, based on Erlang's queue module, which is an efficient implementation of double ended fifo queues
Differences between Quex and Erlang's queue module are a more Elixir
friendly API (subject as first argument) and implementations of the
Enumerable
, Collectable
and Inspect
protocols.
Examples
iex> q = Quex.new |> Quex.put(1) |> Quex.put(2)
Quex.new([1, 2])
iex> Quex.pop(q)
{1, Quex.new([2])}
iex> Quex.new([1, 2, 3, 4]) |> Enum.take_while(&(&1 < 3))
[1, 2]
iex> for n <- 1..4, into: Quex.new(), do: n * n
Quex.new([1, 4, 9, 16])
Summary
Functions
Remove the first value from the front of the queue
Remove the last value from the rear of the queue
Converts Erlang's queue data type to a queue
Join two queues
Returns true if the given value exists in the queue
Creates a new empty queue
Creates a new queue from a list
Get the first value from the front of the queue without removing it
Get the last value from the rear of the queue without removing it
Pop the first value from the front of the queue
Pop the last value from the rear of the queue
Puts the given value at the end the queue
Puts the given value at the front of the queue
Returns the number of items in the queue
Converts a queue to Erlang's queue data type
Converts a queue to a list
Types
Functions
Remove the first value from the front of the queue
Returns the rest of the queue or :empty
if the queue has no items.
Remove the last value from the rear of the queue
Returns the rest of the queue or :empty
if the queue has no items.
Converts Erlang's queue data type to a queue
Join two queues
It effectively appends the second queue to the first queue.
Returns true if the given value exists in the queue
@spec new() :: t()
Creates a new empty queue
Creates a new queue from a list
The first element in the list will be the front item of the queue.
Get the first value from the front of the queue without removing it
Returns the {:ok, value}
or :empty
if the queue has no items.
Get the last value from the rear of the queue without removing it
Returns the {:ok, value}
or :empty
if the queue has no items.
Pop the first value from the front of the queue
Returns the value as well the rest of the queue or :empty
if the queue has
no items.
Pop the last value from the rear of the queue
Returns the value as well the rest of the queue or :empty
if the queue has
no items.
Puts the given value at the end the queue
Puts the given value at the front of the queue
This means that it will be the first item in the queue to pop, peek, or drop.
@spec size(t()) :: non_neg_integer()
Returns the number of items in the queue
Converts a queue to Erlang's queue data type
Converts a queue to a list
The front item of the queue will be the first element in the list.