Queue
Edit on GitHubA 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.
Types
Type declarations included in the Queue module.
Queue.Queue
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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
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
version | changes |
---|---|
0.5.4 | Originally a module root API |
An empty queue.
Queue.Immutable.isEmpty
Added in 0.6.0
version | changes |
---|---|
0.2.0 | Originally a module root API |
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
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 |
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
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 |
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
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 |
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
version | changes |
---|---|
0.3.2 | Originally a module root API |
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.
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.
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 |