Quick Links
  • -Overview
  • -Language Features
  • -JS Interop
  • -Build System
Documentation
Language Manual
Reference for all language features
ReScript & React
First class bindings for ReactJS
GenType
Seamless TypeScript integration
Reanalyze
Dead Code & Termination analysis
Exploration
Packages
Explore third party libraries and bindings
Syntax Lookup
Discover all syntax constructs
APIPlaygroundBlogCommunity
  • Playground
  • Blog
  • X
  • BlueSky
  • GitHub
  • Forum
Belt Stdlib
Overview
  • Introduction
Basics
  • Array
  • List
  • Float
  • Int
  • Range
  • Id
  • Option
  • Result
Set
  • HashSet
  • HashSetInt
  • HashSetString
  • Set
  • SetDict
  • SetInt
  • SetString
Map
  • HashMap
  • HashMapInt
  • HashMapString
  • Map
  • MapDict
  • MapInt
  • MapString
Mutable Collections
  • MutableMap
  • MutableMapInt
  • MutableMapString
  • MutableQueue
    • t
    • add
    • clear
    • copy
    • forEach
    • forEachU
    • fromArray
    • isEmpty
    • make
    • map
    • mapU
    • peek
    • peekExn
    • peekUndefined
    • pop
    • popExn
    • popUndefined
    • reduce
    • reduceU
    • size
    • toArray
    • transfer
  • MutableSet
  • MutableSetInt
  • MutableSetString
  • MutableStack
Sort Collections
  • SortArray
  • SortArrayInt
  • SortArrayString
Utilities
  • Debug
API / Belt / MutableQueue

MutableQueue

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

t

RES
type t<'a>

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

make

RES
let make: unit => t<'a>

Returns a new queue, initially empty.

clear

RES
let clear: t<'a> => unit

Discard all elements from the queue.

isEmpty

RES
let isEmpty: t<'a> => bool

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

fromArray

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

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

add

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

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

peek

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

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

peekUndefined

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

peekUndefined(q) returns undefined if not found.

peekExn

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

raise an exception if q is empty

pop

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

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

popUndefined

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

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

popExn

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

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

copy

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

copy(q) returns a fresh queue.

size

RES
let size: t<'a> => int

Returns the number of elements in a queue.

mapU

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

map

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

forEachU

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

forEach

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

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

reduceU

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

reduce

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

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.

transfer

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

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.

toArray

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

First added will be in the beginning of the array.

© 2024 The ReScript Project

Software and assets distribution powered by KeyCDN.

About
  • Community
  • ReScript Association
Find us on