ESC
No recent searches
Search by
Standard Library  /  Queue

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 GitHub

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.
from "queue" include Queue

Types

Type declarations included in the Queue module.

Queue.Queue

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.
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:

?size: The initial storage size of the queue

Returns:

Queue<a>: An empty queue

Queue.isEmpty

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

Checks if the given queue contains no items.

Parameters:

queue: The queue to check

Returns:

Bool: true if the queue has no items or false otherwise

Queue.size

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

Computes the size of the input queue.

Parameters:

queue: The queue to inspect

Returns:

Number: The count of the items in the queue

Queue.peek

Added 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:

queue: The queue to inspect

Returns:

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.
push : (value: a, queue: Queue<a>) => Void

Adds a new item to the end of the queue.

Parameters:

value: The item to be added
queue: The queue being updated

Queue.pop

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

Removes the item at the beginning of the queue.

Parameters:

queue: The queue being updated

Returns:

Option<a>: The element removed from the queue

Queue.toList

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

Converts a queue into a list of its elements.

Parameters:

queue: The queue to convert

Returns:

List<a>: A list containing all queue values

Queue.fromList

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

Creates a queue from a list.

Parameters:

list: The list to convert

Returns:

Queue<a>: A queue containing all list values

Queue.clear

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

Clears the queue by removing all of its elements

Parameters:

queue: The queue to clear

Queue.copy

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

Produces a shallow copy of the input queue.

Parameters:

queue: The queue to copy

Returns:

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

Queue.toArray

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

Converts a queue into an array of its values.

Parameters:

queue: The queue to convert

Returns:

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

Queue.fromArray

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

Creates a queue from an array.

Parameters:

arr: The array to convert

Returns:

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

Queue.(==)

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

Checks if two queues are equivalent by value.

Parameters:

queue1: The first queue to compare
queue2: The second queue to compare

Returns:

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

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
empty : ImmutableQueue<a>

An empty queue.

Queue.Immutable.isEmpty

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

Checks if the given queue contains any values.

Parameters:

queue: The queue to check

Returns:

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
peek : (queue: ImmutableQueue<a>) => Option<a>

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

Parameters:

queue: The queue to inspect

Returns:

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
push : (value: a, queue: ImmutableQueue<a>) => ImmutableQueue<a>

Adds a value to the end of the queue.

Parameters:

value: The value to append
queue: The queue to update

Returns:

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
pop : (queue: ImmutableQueue<a>) => ImmutableQueue<a>

Dequeues the next value in the queue.

Parameters:

queue: The queue to change

Returns:

ImmutableQueue<a>: An updated queue

Queue.Immutable.size

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

Get the number of values in a queue.

Parameters:

queue: The queue to inspect

Returns:

Number: The number of values in the queue

Queue.Immutable.toList

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

Converts a queue into a list of its elements.

Parameters:

queue: The queue to convert

Returns:

List<a>: A list containing all queue values

Queue.Immutable.fromList

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

Creates a queue from a list.

Parameters:

list: The list to convert

Returns:

ImmutableQueue<a>: A queue containing all list values

Sign up for farm-to-inbox developer news

You can unsubscribe at any time. Read our privacy policy.

Copyright © 2024 The Grain Programming Language