API / Belt / Belt_MutableQueue

Belt_MutableQueue

A FIFO (first in first out) queue data structure.

t

The type of queues containing elements of type('a).

type t<'a>

make

Returns a new queue, initially empty.

let make: unit => t<'a>

clear

Discard all elements from the queue.

let clear: t<'a> => unit

isEmpty

Returns true if the given queue is empty, false otherwise.

let isEmpty: t<'a> => bool

fromArray

fromArray a is equivalent to Array.forEach(a, add(q, a));

let fromArray: array<'a> => t<'a>

add

add(q, x) adds the element x at the end of the queue q.

let add: (t<'a>, 'a) => unit

peek

peekOpt(q) returns the first element in queue q, without removing it from the queue.

let peek: t<'a> => option<'a>

peekUndefined

peekUndefined(q) returns undefined if not found.

let peekUndefined: t<'a> => Js.undefined<'a>

peekExn

raise an exception if q is empty

let peekExn: t<'a> => 'a

pop

pop(q) removes and returns the first element in queue q.

let pop: t<'a> => option<'a>

popUndefined

popUndefined(q) removes and returns the first element in queue q. it will return undefined if it is already empty.

let popUndefined: t<'a> => Js.undefined<'a>

popExn

popExn(q) raise an exception if q is empty.

let popExn: t<'a> => 'a

copy

copy(q) returns a fresh queue.

let copy: t<'a> => t<'a>

size

Returns the number of elements in a queue.

let size: t<'a> => int

mapU

let mapU: (t<'a>, (. 'a) => 'b) => t<'b>

map

let map: (t<'a>, 'a => 'b) => t<'b>

forEachU

let forEachU: (t<'a>, (. 'a) => unit) => unit

forEach

forEach(q, f) appliesfin turn to all elements ofq`, from the least recently entered to the most recently entered. The queue itself is unchanged.

let forEach: (t<'a>, 'a => unit) => unit

reduceU

let reduceU: (t<'a>, 'b, (. 'b, 'a) => 'b) => 'b

reduce

reduce(q, accu, f) is equivalent to List.reduce(l, accu, f), where l is the list of q's elements. The queue remains unchanged.

let reduce: (t<'a>, 'b, ('b, 'a) => 'b) => 'b

transfer

transfer(q1, q2) adds all of q1's elements at the end of the queue q2, then clears q1. It is equivalent to the sequence forEach((x) => add(x, q2), q1);; clear q1, but runs in constant time.

let transfer: (t<'a>, t<'a>) => unit

toArray

First added will be in the beginning of the array.

let toArray: t<'a> => array<'a>