Okasaki.Queue (Okasaki v1.0.1) View Source

Public interface to work with queue-like structures.

Link to this section Summary

Functions

Returns a new empty queue.

True if the queue does not contain any elements.

Inserts a new element into the end of the queue. Returns the new queue.

Checks if item is one of the elements inside of queue.

Creates a new deque.

Attempts to remove the front element of the queue

Returns the number of elements inside the queue. For most queue implementations, this is a O(1) procedure, because the size is explicitly kept.

A function to remove elements from the front of a queue, until the function returns false.

Transforms the queue into a list.

Link to this section Functions

Returns a new empty queue.

Optionally, the implementation: SomeModuleName can be passed. (See the list of implementations in the module documentation of the Okasaki module.)

This can also be overridden on an application-wide level, by the configuration:

config :okasaki, default_queue_implementation: Queue.Implementation.Module.Name

By default, Okasaki.Implementations.ConstantQueue is used.

True if the queue does not contain any elements.

Inserts a new element into the end of the queue. Returns the new queue.

Checks if item is one of the elements inside of queue.

Uses Erlang's built-in structural term comparison.

Link to this function

new(enumerable \\ [], opts \\ [])

View Source

Creates a new deque.

The first parameter is an enumerable that the queue will be filled with. The second parameter is a list of options, which are the same as empty/1 expects.

Attempts to remove the front element of the queue:

  • Returns {:error, :empty} if the queue is empty.
  • Returns {:ok, {item, queue_without_item}} if it succeeded.

Returns the number of elements inside the queue. For most queue implementations, this is a O(1) procedure, because the size is explicitly kept.

A function to remove elements from the front of a queue, until the function returns false.

Then, returns {list_of_removed_items, rest_of_queue}

In contrast to Enum.split_while, the unused rest of the queue is not suddenly transformed into a list, but is still a queue.

Transforms the queue into a list.