This is the latest docs version
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
  • Community
  • X
  • Bluesky
  • GitHub
  • Forum
Belt Module
Overview
Belt
submodules
  • Array
  • Float
  • HashMap
    • String
    • Int
    HashSet
    • String
    • Int
    Id
    • MakeHashable
    • MakeHashableU
    • MakeComparable
    • MakeComparableU
  • Int
  • List
  • Map
    • Dict
    • String
    • Int
    MutableMap
    • String
    • Int
  • MutableQueue
  • MutableSet
    • String
    • Int
  • MutableStack
  • Option
  • Range
  • Result
  • Set
    • Dict
    • String
    • Int
    SortArray
    • v
      strictlySortedLengthU
    • v
      strictlySortedLength
    • v
      isSortedU
    • v
      isSorted
    • v
      stableSortInPlaceByU
    • v
      stableSortInPlaceBy
    • v
      stableSortByU
    • v
      stableSortBy
    • v
      binarySearchByU
    • v
      binarySearchBy
    • v
      unionU
    • v
      union
    • v
      intersectU
    • v
      intersect
    • v
      diffU
    • v
      diff
    • String
    • Int
    API / Belt / Sortarray

    SortArray

    A module for Array sort relevant utiliites

    strictlySortedLengthU

    RESCRIPT
    let strictlySortedLengthU: (array<'a>, ('a, 'a) => bool) => int

    strictlySortedLength

    RESCRIPT
    let strictlySortedLength: (array<'a>, ('a, 'a) => bool) => int

    strictlySortedLenght(xs, cmp); return +n means increasing order -n means negative order

    Examples

    RESCRIPT
    Belt.SortArray.strictlySortedLength([1, 2, 3, 4, 3], (x, y) => x < y) == 4 Belt.SortArray.strictlySortedLength([], (x, y) => x < y) == 0 Belt.SortArray.strictlySortedLength([1], (x, y) => x < y) == 1 Belt.SortArray.strictlySortedLength([4, 3, 2, 1], (x, y) => x < y) == -4

    isSortedU

    RESCRIPT
    let isSortedU: (array<'a>, ('a, 'a) => int) => bool

    isSorted

    RESCRIPT
    let isSorted: (array<'a>, ('a, 'a) => int) => bool

    isSorted(arr, cmp): Returns true if array is increasingly sorted (equal is okay)

    stableSortInPlaceByU

    RESCRIPT
    let stableSortInPlaceByU: (array<'a>, ('a, 'a) => int) => unit

    stableSortInPlaceBy

    RESCRIPT
    let stableSortInPlaceBy: (array<'a>, ('a, 'a) => int) => unit

    stableSortByU

    RESCRIPT
    let stableSortByU: (array<'a>, ('a, 'a) => int) => array<'a>

    stableSortBy

    RESCRIPT
    let stableSortBy: (array<'a>, ('a, 'a) => int) => array<'a>

    stableSortBy(xs, cmp): Returns a fresh array Sort xs in place using comparator cmp, the stable means if the elements are equal, their order will be preserved

    binarySearchByU

    RESCRIPT
    let binarySearchByU: (array<'a>, 'a, ('a, 'a) => int) => int

    binarySearchBy

    RESCRIPT
    let binarySearchBy: (array<'a>, 'a, ('a, 'a) => int) => int

    If value is not found and value is less than one or more elements in array, the negative number returned is the bitwise complement of the index of the first element that is larger than value.

    If value is not found and value is greater than all elements in array, the negative number returned is the bitwise complement of (the index of the last element plus 1)for example, if key is smaller than all elements return -1 since lnot(-1) == 0 if key is larger than all elements return lnot(-1) == 0 since lnot(- (len + 1)) == len

    Examples

    RESCRIPT
    Belt.SortArray.binarySearchBy([1, 2, 3, 4, 33, 35, 36], 33, Pervasives.compare) == 4 lnot(Belt.SortArray.binarySearchBy([1, 3, 5, 7], 4, Pervasives.compare)) == 2

    unionU

    RESCRIPT
    let unionU: ( array<'a>, int, int, array<'a>, int, int, array<'a>, int, ('a, 'a) => int, ) => int

    union

    RESCRIPT
    let union: ( array<'a>, int, int, array<'a>, int, int, array<'a>, int, ('a, 'a) => int, ) => int

    union src src1ofs src1len src2 src2ofs src2len dst dstofs cmp assume src and src2 is strictly sorted. for equivalent elements, it is picked from src also assume that dst is large enough to store all elements

    intersectU

    RESCRIPT
    let intersectU: ( array<'a>, int, int, array<'a>, int, int, array<'a>, int, ('a, 'a) => int, ) => int

    intersect

    RESCRIPT
    let intersect: ( array<'a>, int, int, array<'a>, int, int, array<'a>, int, ('a, 'a) => int, ) => int

    union src src1ofs src1len src2 src2ofs src2len dst dstofs cmp

    return the offset in the output array

    diffU

    RESCRIPT
    let diffU: ( array<'a>, int, int, array<'a>, int, int, array<'a>, int, ('a, 'a) => int, ) => int

    diff

    RESCRIPT
    let diff: ( array<'a>, int, int, array<'a>, int, int, array<'a>, int, ('a, 'a) => int, ) => int
    Types and values
    • v
      strictlySortedLengthU
    • v
      strictlySortedLength
    • v
      isSortedU
    • v
      isSorted
    • v
      stableSortInPlaceByU
    • v
      stableSortInPlaceBy
    • v
      stableSortByU
    • v
      stableSortBy
    • v
      binarySearchByU
    • v
      binarySearchBy
    • v
      unionU
    • v
      union
    • v
      intersectU
    • v
      intersect
    • v
      diffU
    • v
      diff

    © 2025 The ReScript Project

    Software and assets distribution powered by KeyCDN.

    About
    • Community
    • ReScript Association
    Find us on