Queue

GitHub   Edit on GitHub

A queue is a FIFO (first-in-first-out) data structure where new values are added to the end and retrieved or removed from the beginning.

The default implementation is mutable, but an immutable queue implementation is available in the Immutable submodule.

Added in 0.2.0 No other changes yet.
1
from "queue" include Queue

Types

Type declarations included in the Queue module.

Queue.Queue

1
type Queue<a>

A mutable FIFO (first-in-first-out) data structure.


Values

Functions and constants included in the Queue module.

Queue.make

Added in 0.6.0 No other changes yet.
1
make : (?size: Number) => Queue<a>

Creates a new queue with an initial storage of the given size. As values are added or removed, the internal storage may grow or shrink. Generally, you won’t need to care about the storage size of your map and can use the default size.

Parameters:

param type description
?size Number The initial storage size of the queue

Returns:

type description
Queue<a> An empty queue

Queue.isEmpty

Added in 0.6.0 No other changes yet.
1
isEmpty : (queue: Queue<a>) => Bool

Checks if the given queue contains no items.

Parameters:

param type description
queue Queue<a> The queue to check

Returns:

type description
Bool true if the queue has no items or false otherwise

Queue.size

Added in 0.6.0 No other changes yet.
1
size : (queue: Queue<a>) => Number

Computes the size of the input queue.

Parameters:

param type description
queue Queue<a> The queue to inspect

Returns:

type description
Number The count of the items in the queue

Queue.peek

Added in 0.6.0 No other changes yet.
1
peek : (queue: Queue<a>) => Option<a>

Provides the value at the beginning of the queue, if it exists.

Parameters:

param type description
queue Queue<a> The queue to inspect

Returns:

type description
Option<a> Some(value) containing the value at the beginning of the queue or None otherwise.

Queue.push

Added in 0.6.0 No other changes yet.
1
push : (value: a, queue: Queue<a>) => Void

Adds a new item to the end of the queue.

Parameters:

param type description
value a The item to be added
queue Queue<a> The queue being updated

Queue.pop

Added in 0.6.0 No other changes yet.
1
pop : (queue: Queue<a>) => Option<a>

Removes the item at the beginning of the queue.

Parameters:

param type description
queue Queue<a> The queue being updated

Returns:

type description
Option<a> The element removed from the queue

Queue.toList

Added in 0.6.0 No other changes yet.
1
toList : (queue: Queue<a>) => List<a>

Converts a queue into a list of its elements.

Parameters:

param type description
queue Queue<a> The queue to convert

Returns:

type description
List<a> A list containing all queue values

Queue.fromList

Added in 0.6.0 No other changes yet.
1
fromList : (list: List<a>) => Queue<a>

Creates a queue from a list.

Parameters:

param type description
list List<a> The list to convert

Returns:

type description
Queue<a> A queue containing all list values

Queue.clear

Added in 0.6.0 No other changes yet.
1
clear : (queue: Queue<a>) => Void

Clears the queue by removing all of its elements

Parameters:

param type description
queue Queue<a> The queue to clear

Queue.copy

Added in 0.6.0 No other changes yet.
1
copy : (queue: Queue<a>) => Queue<a>

Produces a shallow copy of the input queue.

Parameters:

param type description
queue Queue<a> The queue to copy

Returns:

type description
Queue<a> A new queue containing the elements from the input

Queue.toArray

Added in 0.6.0 No other changes yet.
1
toArray : (queue: Queue<a>) => Array<a>

Converts a queue into an array of its values.

Parameters:

param type description
queue Queue<a> The queue to convert

Returns:

type description
Array<a> An array containing all values from the given queue

Queue.fromArray

Added in 0.6.0 No other changes yet.
1
fromArray : (arr: Array<a>) => Queue<a>

Creates a queue from an array.

Parameters:

param type description
arr Array<a> The array to convert

Returns:

type description
Queue<a> A queue containing all values from the array

Queue.(==)

Added in 0.6.0 No other changes yet.
1
(==) : (queue1: Queue<a>, queue2: Queue<a>) => Bool

Checks if two queues are equivalent by value.

Parameters:

param type description
queue1 Queue<a> The first queue to compare
queue2 Queue<a> The second queue to compare

Returns:

type description
Bool true if the queues are equivalent or false otherwise

Queue.Immutable

An immutable queue implementation.

Types

Type declarations included in the Queue.Immutable module.

Queue.Immutable.ImmutableQueue

1
type ImmutableQueue<a>

An immutable FIFO (first-in-first-out) data structure.

Values

Functions and constants included in the Queue.Immutable module.

Queue.Immutable.empty

Added in 0.6.0
versionchanges
0.5.4Originally a module root API
1
empty : ImmutableQueue<a>

An empty queue.

Queue.Immutable.isEmpty

Added in 0.6.0
versionchanges
0.2.0Originally a module root API
1
isEmpty : (queue: ImmutableQueue<a>) => Bool

Checks if the given queue contains any values.

Parameters:

param type description
queue ImmutableQueue<a> The queue to check

Returns:

type description
Bool true if the given queue is empty or false otherwise

Queue.Immutable.peek

Added in 0.6.0
versionchanges
0.2.0Originally named `head`
0.3.2Deprecated `head` function
0.3.2Originally a module root API
0.4.0Removed `head` function
1
peek : (queue: ImmutableQueue<a>) => Option<a>

Returns the value at the beginning of the queue. It is not removed from the queue.

Parameters:

param type description
queue ImmutableQueue<a> The queue to inspect

Returns:

type description
Option<a> Some(value) containing the value at the beginning of the queue, or None if the queue is empty

Queue.Immutable.push

Added in 0.6.0
versionchanges
0.2.0Originally named `enqueue`
0.3.2Deprecated `enqueue` function
0.3.2Originally a module root API
0.4.0Removed `enqueue` function
1
push : (value: a, queue: ImmutableQueue<a>) => ImmutableQueue<a>

Adds a value to the end of the queue.

Parameters:

param type description
value a The value to append
queue ImmutableQueue<a> The queue to update

Returns:

type description
ImmutableQueue<a> An updated queue

Queue.Immutable.pop

Added in 0.6.0
versionchanges
0.2.0Originally named `dequeue`
0.3.2Deprecated `dequeue` function
0.3.2Originally a module root API
0.4.0Removed `dequeue` function
1
pop : (queue: ImmutableQueue<a>) => ImmutableQueue<a>

Dequeues the next value in the queue.

Parameters:

param type description
queue ImmutableQueue<a> The queue to change

Returns:

type description
ImmutableQueue<a> An updated queue

Queue.Immutable.size

Added in 0.6.0
versionchanges
0.3.2Originally a module root API
1
size : (queue: ImmutableQueue<a>) => Number

Get the number of values in a queue.

Parameters:

param type description
queue ImmutableQueue<a> The queue to inspect

Returns:

type description
Number The number of values in the queue

Queue.Immutable.toList

Added in 0.6.0 No other changes yet.
1
toList : (queue: ImmutableQueue<a>) => List<a>

Converts a queue into a list of its elements.

Parameters:

param type description
queue ImmutableQueue<a> The queue to convert

Returns:

type description
List<a> A list containing all queue values

Queue.Immutable.fromList

Added in 0.6.0 No other changes yet.
1
fromList : (list: List<a>) => ImmutableQueue<a>

Creates a queue from a list.

Parameters:

param type description
list List<a> The list to convert

Returns:

type description
ImmutableQueue<a> A queue containing all list values
This is a notification!