Queue
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.
Edit on GitHubThe default implementation is mutable, but an immutable queue
implementation is available in the Immutable submodule.
Added in 0.2.0
No other changes yet.
from "queue" include Queue
Type declarations included in the Queue module.
type Queue<a>
A mutable FIFO (first-in-first-out) data structure.
Functions and constants included in the Queue module.
Added in 0.6.0
No other changes yet.
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 |
?size: The initial storage size of the queueReturns:
| type | description |
|---|---|
Queue<a> | An empty queue |
Queue<a>: An empty queueAdded in 0.6.0
No other changes yet.
isEmpty : (queue: Queue<a>) => Bool
Checks if the given queue contains no items.
Parameters:
| param | type | description |
|---|---|---|
queue | Queue<a> | The queue to check |
queue: The queue to checkReturns:
| type | description |
|---|---|
Bool | true if the queue has no items or false otherwise |
Bool: true if the queue has no items or false otherwiseAdded in 0.6.0
No other changes yet.
size : (queue: Queue<a>) => Number
Computes the size of the input queue.
Parameters:
| param | type | description |
|---|---|---|
queue | Queue<a> | The queue to inspect |
queue: The queue to inspectReturns:
| type | description |
|---|---|
Number | The count of the items in the queue |
Number: The count of the items in the queueAdded in 0.6.0
No other changes yet.
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 |
queue: The queue to inspectReturns:
| type | description |
|---|---|
Option<a> | Some(value) containing the value at the beginning of the queue or None otherwise. |
Option<a>: Some(value) containing the value at the beginning of the queue or None otherwise.Added in 0.6.0
No other changes yet.
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 |
value: The item to be addedqueue: The queue being updatedAdded in 0.6.0
No other changes yet.
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 |
queue: The queue being updatedReturns:
| type | description |
|---|---|
Option<a> | The element removed from the queue |
Option<a>: The element removed from the queueAdded in 0.6.0
No other changes yet.
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 |
queue: The queue to convertReturns:
| type | description |
|---|---|
List<a> | A list containing all queue values |
List<a>: A list containing all queue valuesAdded in 0.6.0
No other changes yet.
fromList : (list: List<a>) => Queue<a>
Creates a queue from a list.
Parameters:
| param | type | description |
|---|---|---|
list | List<a> | The list to convert |
list: The list to convertReturns:
| type | description |
|---|---|
Queue<a> | A queue containing all list values |
Queue<a>: A queue containing all list valuesAdded in 0.6.0
No other changes yet.
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: The queue to clearAdded in 0.6.0
No other changes yet.
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 |
queue: The queue to copyReturns:
| type | description |
|---|---|
Queue<a> | A new queue containing the elements from the input |
Queue<a>: A new queue containing the elements from the inputAdded in 0.6.0
No other changes yet.
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 |
queue: The queue to convertReturns:
| type | description |
|---|---|
Array<a> | An array containing all values from the given queue |
Array<a>: An array containing all values from the given queueAdded in 0.6.0
No other changes yet.
fromArray : (arr: Array<a>) => Queue<a>
Creates a queue from an array.
Parameters:
| param | type | description |
|---|---|---|
arr | Array<a> | The array to convert |
arr: The array to convertReturns:
| type | description |
|---|---|
Queue<a> | A queue containing all values from the array |
Queue<a>: A queue containing all values from the arrayAdded in 0.6.0
No other changes yet.
(==) : (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 |
queue1: The first queue to comparequeue2: The second queue to compareReturns:
| type | description |
|---|---|
Bool | true if the queues are equivalent or false otherwise |
Bool: true if the queues are equivalent or false otherwiseAn immutable queue implementation.
Type declarations included in the Queue.Immutable module.
type ImmutableQueue<a>
An immutable FIFO (first-in-first-out) data structure.
Functions and constants included in the Queue.Immutable module.
Added in 0.6.0
| version | changes |
|---|---|
0.5.4 | Originally a module root API |
empty : ImmutableQueue<a>
An empty queue.
Added in 0.6.0
| version | changes |
|---|---|
0.2.0 | Originally a module root API |
isEmpty : (queue: ImmutableQueue<a>) => Bool
Checks if the given queue contains any values.
Parameters:
| param | type | description |
|---|---|---|
queue | ImmutableQueue<a> | The queue to check |
queue: The queue to checkReturns:
| type | description |
|---|---|
Bool | true if the given queue is empty or false otherwise |
Bool: true if the given queue is empty or false otherwiseAdded in 0.6.0
| version | changes |
|---|---|
0.2.0 | Originally named `head` |
0.3.2 | Deprecated `head` function |
0.3.2 | Originally a module root API |
0.4.0 | Removed `head` function |
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 |
queue: The queue to inspectReturns:
| type | description |
|---|---|
Option<a> | Some(value) containing the value at the beginning of the queue, or None if the queue is empty |
Option<a>: Some(value) containing the value at the beginning of the queue, or None if the queue is emptyAdded in 0.6.0
| version | changes |
|---|---|
0.2.0 | Originally named `enqueue` |
0.3.2 | Deprecated `enqueue` function |
0.3.2 | Originally a module root API |
0.4.0 | Removed `enqueue` function |
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 |
value: The value to appendqueue: The queue to updateReturns:
| type | description |
|---|---|
ImmutableQueue<a> | An updated queue |
ImmutableQueue<a>: An updated queueAdded in 0.6.0
| version | changes |
|---|---|
0.2.0 | Originally named `dequeue` |
0.3.2 | Deprecated `dequeue` function |
0.3.2 | Originally a module root API |
0.4.0 | Removed `dequeue` function |
pop : (queue: ImmutableQueue<a>) => ImmutableQueue<a>
Dequeues the next value in the queue.
Parameters:
| param | type | description |
|---|---|---|
queue | ImmutableQueue<a> | The queue to change |
queue: The queue to changeReturns:
| type | description |
|---|---|
ImmutableQueue<a> | An updated queue |
ImmutableQueue<a>: An updated queueAdded in 0.6.0
| version | changes |
|---|---|
0.3.2 | Originally a module root API |
size : (queue: ImmutableQueue<a>) => Number
Get the number of values in a queue.
Parameters:
| param | type | description |
|---|---|---|
queue | ImmutableQueue<a> | The queue to inspect |
queue: The queue to inspectReturns:
| type | description |
|---|---|
Number | The number of values in the queue |
Number: The number of values in the queueAdded in 0.6.0
No other changes yet.
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 |
queue: The queue to convertReturns:
| type | description |
|---|---|
List<a> | A list containing all queue values |
List<a>: A list containing all queue valuesAdded in 0.6.0
No other changes yet.
fromList : (list: List<a>) => ImmutableQueue<a>
Creates a queue from a list.
Parameters:
| param | type | description |
|---|---|---|
list | List<a> | The list to convert |
list: The list to convertReturns:
| type | description |
|---|---|
ImmutableQueue<a> | A queue containing all list values |
ImmutableQueue<a>: A queue containing all list values