DocsPlaygroundBlogCommunityPackages
  • Playground
  • Blog
  • Community
  • Packages
  • X
  • Bluesky
  • GitHub
  • Forum
Language ManualAPISyntax LookupReact
Overview
Stdlib
submodules
  • Array
  • ArrayBuffer
  • AsyncIterator
  • BigInt
  • BigInt64Array
    • Constants
    BigUint64Array
    • Constants
  • Bool
  • Console
  • DataView
  • Date
    • UTC
  • Dict
  • Error
    • URIError
    • TypeError
    • SyntaxError
    • ReferenceError
    • RangeError
    • EvalError
  • Exn
  • Float
    • Constants
    Float32Array
    • Constants
    Float64Array
    • Constants
    Int
    • Ref
    • Bitwise
    • Constants
    Int16Array
    • Constants
    Int32Array
    • Constants
    Int8Array
    • Constants
  • IntervalId
  • Intl
    • Segments
    • Segmenter
    • RelativeTimeFormat
    • PluralRules
    • NumberFormat
      • Grouping
    • Locale
    • ListFormat
    • DateTimeFormat
    • Collator
    • Common
  • Iterator
  • JSON
    • Decode
    • Encode
    • Classify
    JsError
    • URIError
    • TypeError
    • SyntaxError
    • ReferenceError
    • RangeError
    • EvalError
  • JsExn
  • Lazy
  • List
  • Map
  • Math
    • Int
    • Constants
  • Null
  • Nullable
  • Object
  • Option
  • Ordering
  • Pair
  • Promise
  • RegExp
    • Result
  • Result
  • Set
  • String
  • Symbol
  • TimeoutId
  • Type
    • Classify
  • TypedArray
    • t
      t
    • v
      get
    • v
      set
    • v
      buffer
    • v
      byteLength
    • v
      byteOffset
    • v
      setArray
    • v
      setArrayFrom
    • v
      length
    • v
      copyAllWithin
    • v
      copyWithinToEnd
      D
    • v
      copyWithin
    • v
      fillAll
    • v
      fillToEnd
      D
    • v
      fill
    • v
      reverse
    • v
      toReversed
    • v
      sort
    • v
      toSorted
    • v
      with
    • v
      includes
    • v
      indexOf
    • v
      indexOfFrom
    • v
      joinWith
    • v
      lastIndexOf
    • v
      lastIndexOfFrom
    • v
      slice
    • v
      sliceToEnd
      D
    • v
      copy
    • v
      subarray
    • v
      subarrayToEnd
      D
    • v
      toString
    • v
      toLocaleString
    • v
      every
    • v
      everyWithIndex
    • v
      filter
    • v
      filterWithIndex
    • v
      find
    • v
      findWithIndex
    • v
      findLast
    • v
      findLastWithIndex
    • v
      findIndex
    • v
      findIndexWithIndex
    • v
      findLastIndex
    • v
      findLastIndexWithIndex
    • v
      forEach
    • v
      forEachWithIndex
    • v
      map
    • v
      mapWithIndex
    • v
      reduce
    • v
      reduceWithIndex
    • v
      reduceRight
    • v
      reduceRightWithIndex
    • v
      some
    • v
      someWithIndex
    • v
      ignore
  • Uint16Array
    • Constants
    Uint32Array
    • Constants
    Uint8Array
    • Constants
    Uint8ClampedArray
    • Constants
  • WeakMap
  • WeakSet
  • Docs / API / Stdlib / Typedarray

    TypedArray

    t

    RESCRIPT
    type t<'a>

    get

    RESCRIPT
    let get: (t<'a>, int) => option<'a>

    get(typedArray, index) returns the element at index of typedArray. Returns None if the index does not exist in the typed array. Equivalent to doing typedArray[index] in JavaScript.

    Examples

    RESCRIPT
    let view = Int32Array.fromArray([1, 2, 3]) TypedArray.get(view, 0) == Some(1) TypedArray.get(view, 10) == None

    set

    RESCRIPT
    let set: (t<'a>, int, 'a) => unit

    set(typedArray, index, item) sets the provided item at index of typedArray.

    Beware this will mutate the array.

    Examples

    RESCRIPT
    let view = Int32Array.fromArray([1, 2]) TypedArray.set(view, 1, 5) TypedArray.get(view, 1) == Some(5)

    buffer

    RESCRIPT
    let buffer: t<'a> => ArrayBuffer.t

    buffer(typedArray) returns the underlying ArrayBuffer backing this view.

    See TypedArray.prototype.buffer on MDN.

    byteLength

    RESCRIPT
    let byteLength: t<'a> => int

    byteLength(typedArray) returns the length in bytes of the view.

    See TypedArray.prototype.byteLength on MDN.

    Examples

    RESCRIPT
    let view = Int32Array.fromArray([1, 2]) TypedArray.byteLength(view) == 8

    byteOffset

    RESCRIPT
    let byteOffset: t<'a> => int

    byteOffset(typedArray) returns the offset in bytes from the start of the buffer.

    See TypedArray.prototype.byteOffset on MDN.

    setArray

    RESCRIPT
    let setArray: (t<'a>, array<'a>) => unit

    setArray(target, source) copies the values from source into target, mutating it.

    See TypedArray.prototype.set on MDN.

    Examples

    RESCRIPT
    let view = Int32Array.fromArray([0, 0]) TypedArray.setArray(view, [1, 2]) TypedArray.toString(view) == "1,2"

    setArrayFrom

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

    setArrayFrom(target, source, index) copies source into target starting at index.

    See TypedArray.prototype.set on MDN.

    Examples

    RESCRIPT
    let view = Int32Array.fromArray([0, 0, 0]) TypedArray.setArrayFrom(view, [5, 6], 1) TypedArray.toString(view) == "0,5,6"

    length

    RESCRIPT
    let length: t<'a> => int

    length(typedArray) returns the number of elements.

    See TypedArray.prototype.length on MDN.

    Examples

    RESCRIPT
    let view = Int32Array.fromArray([1, 2, 3]) TypedArray.length(view) == 3

    copyAllWithin

    RESCRIPT
    let copyAllWithin: (t<'a>, ~target: int) => array<'a>

    copyAllWithin(typedArray, ~target) copies values starting at index 0 over the positions beginning at target.

    Beware this will mutate the typed array.

    See TypedArray.prototype.copyWithin on MDN.

    Examples

    RESCRIPT
    let view = Int32Array.fromArray([10, 20, 30]) let _ = TypedArray.copyAllWithin(view, ~target=1) TypedArray.toString(view) == "10,10,20"

    copyWithinToEnd

    Deprecated

    RESCRIPT
    let copyWithinToEnd: (t<'a>, ~target: int, ~start: int) => array<'a>

    copyWithinToEnd(typedArray, ~target, ~start) copies values from start through the end of the view into the range beginning at target.

    Beware this will mutate the typed array.

    See TypedArray.prototype.copyWithin on MDN.

    Examples

    RESCRIPT
    let view = Int32Array.fromArray([1, 2, 3, 4]) let _ = TypedArray.copyWithinToEnd(view, ~target=0, ~start=2) TypedArray.toString(view) == "3,4,3,4"

    copyWithin

    RESCRIPT
    let copyWithin: (t<'a>, ~target: int, ~start: int, ~end: int=?) => array<'a>

    copyWithin(typedArray, ~target, ~start, ~end) copies the section [start, end) onto the range beginning at target.

    Beware this will mutate the typed array.

    See TypedArray.prototype.copyWithin on MDN.

    Examples

    RESCRIPT
    let view = Int32Array.fromArray([1, 2, 3, 4]) let _ = TypedArray.copyWithin(view, ~target=1, ~start=2, ~end=4) TypedArray.toString(view) == "1,3,4,4"

    fillAll

    RESCRIPT
    let fillAll: (t<'a>, 'a) => t<'a>

    fillAll(typedArray, value) fills every element with value.

    Beware this will mutate the typed array.

    See TypedArray.prototype.fill on MDN.

    Examples

    RESCRIPT
    let view = Int32Array.fromArray([1, 2, 3]) let _ = TypedArray.fillAll(view, 9) TypedArray.toString(view) == "9,9,9"

    fillToEnd

    Deprecated

    RESCRIPT
    let fillToEnd: (t<'a>, 'a, ~start: int) => t<'a>

    fillToEnd(typedArray, value, ~start) fills from start through the end with value.

    Beware this will mutate the typed array.

    fill

    RESCRIPT
    let fill: (t<'a>, 'a, ~start: int, ~end: int=?) => t<'a>

    fill(typedArray, value, ~start, ~end) fills the half-open interval [start, end) with value.

    Beware this will mutate the typed array.

    See TypedArray.prototype.fill on MDN.

    Examples

    RESCRIPT
    let view = Int32Array.fromArray([1, 2, 3, 4]) let _ = TypedArray.fill(view, 0, ~start=1, ~end=3) TypedArray.toString(view) == "1,0,0,4"

    reverse

    RESCRIPT
    let reverse: t<'a> => unit

    reverse(typedArray) reverses the elements of the view in place.

    Beware this will mutate the typed array.

    See TypedArray.prototype.reverse on MDN.

    toReversed

    RESCRIPT
    let toReversed: t<'a> => t<'a>

    toReversed(typedArray) returns a new typed array with the elements in reverse order, leaving the original untouched.

    See TypedArray.prototype.toReversed on MDN.

    Examples

    RESCRIPT
    let view = Int32Array.fromArray([1, 2, 3]) let reversed = TypedArray.toReversed(view) TypedArray.toString(reversed) == "3,2,1" TypedArray.toString(view) == "1,2,3"

    sort

    RESCRIPT
    let sort: (t<'a>, ('a, 'a) => Ordering.t) => unit

    sort(typedArray, comparator) sorts the values in place using comparator.

    Beware this will mutate the typed array.

    See TypedArray.prototype.sort on MDN.

    toSorted

    RESCRIPT
    let toSorted: (t<'a>, ('a, 'a) => Ordering.t) => t<'a>

    toSorted(typedArray, comparator) returns a new typed array containing the sorted values, leaving the original untouched.

    See TypedArray.prototype.toSorted on MDN.

    Examples

    RESCRIPT
    let view = Int32Array.fromArray([3, 1, 2]) let sorted = TypedArray.toSorted(view, Int.compare) TypedArray.toString(sorted) == "1,2,3" TypedArray.toString(view) == "3,1,2"

    with

    RESCRIPT
    let with: (t<'a>, int, 'a) => t<'a>

    with(typedArray, index, value) returns a new typed array where the element at index is replaced with value.

    See TypedArray.prototype.with on MDN.

    Examples

    RESCRIPT
    let view = Int32Array.fromArray([1, 2, 3]) let updated = TypedArray.with(view, 1, 10) TypedArray.toString(updated) == "1,10,3" TypedArray.toString(view) == "1,2,3"

    includes

    RESCRIPT
    let includes: (t<'a>, 'a) => bool

    includes(typedArray, value) returns true if value occurs in the typed array.

    See TypedArray.prototype.includes on MDN.

    Examples

    RESCRIPT
    let view = Int32Array.fromArray([1, 2, 3]) TypedArray.includes(view, 2) == true TypedArray.includes(view, 10) == false

    indexOf

    RESCRIPT
    let indexOf: (t<'a>, 'a) => int

    indexOf(typedArray, value) returns the first index of value, or -1 when not found.

    See TypedArray.prototype.indexOf on MDN.

    indexOfFrom

    RESCRIPT
    let indexOfFrom: (t<'a>, 'a, int) => int

    indexOfFrom(typedArray, value, fromIndex) searches for value starting at fromIndex.

    joinWith

    RESCRIPT
    let joinWith: (t<'a>, string) => string

    joinWith(typedArray, separator) returns a string formed by the elements joined with separator.

    See TypedArray.prototype.join on MDN.

    Examples

    RESCRIPT
    let view = Int32Array.fromArray([1, 2, 3]) TypedArray.joinWith(view, "-") == "1-2-3"

    lastIndexOf

    RESCRIPT
    let lastIndexOf: (t<'a>, 'a) => int

    lastIndexOf(typedArray, value) returns the last index of value, or -1 if not found.

    See TypedArray.prototype.lastIndexOf on MDN.

    lastIndexOfFrom

    RESCRIPT
    let lastIndexOfFrom: (t<'a>, 'a, int) => int

    lastIndexOfFrom(typedArray, value, fromIndex) searches backwards starting at fromIndex.

    slice

    RESCRIPT
    let slice: (t<'a>, ~start: int, ~end: int=?) => t<'a>

    slice(typedArray, ~start, ~end) returns a new typed array containing the elements in [start, end).

    See TypedArray.prototype.slice on MDN.

    sliceToEnd

    Deprecated

    RESCRIPT
    let sliceToEnd: (t<'a>, ~start: int) => t<'a>

    sliceToEnd(typedArray, ~start) returns the elements from start through the end in a new typed array.

    copy

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

    copy(typedArray) produces a shallow copy of the typed array.

    subarray

    RESCRIPT
    let subarray: (t<'a>, ~start: int, ~end: int=?) => t<'a>

    subarray(typedArray, ~start, ~end) returns a new view referencing the same buffer over [start, end).

    See TypedArray.prototype.subarray on MDN.

    subarrayToEnd

    Deprecated

    RESCRIPT
    let subarrayToEnd: (t<'a>, ~start: int) => t<'a>

    subarrayToEnd(typedArray, ~start) returns a new view from start to the end of the buffer.

    toString

    RESCRIPT
    let toString: t<'a> => string

    toString(typedArray) returns a comma-separated string of the elements.

    See TypedArray.prototype.toString on MDN.

    Examples

    RESCRIPT
    Int32Array.fromArray([1, 2])->TypedArray.toString == "1,2"

    toLocaleString

    RESCRIPT
    let toLocaleString: t<'a> => string

    toLocaleString(typedArray) concatenates the elements using locale-aware formatting.

    See TypedArray.prototype.toLocaleString on MDN.

    every

    RESCRIPT
    let every: (t<'a>, 'a => bool) => bool

    every(typedArray, predicate) returns true if predicate returns true for every element.

    See TypedArray.prototype.every on MDN.

    everyWithIndex

    RESCRIPT
    let everyWithIndex: (t<'a>, ('a, int) => bool) => bool

    everyWithIndex(typedArray, checker) is like every but provides the element index to checker.

    filter

    RESCRIPT
    let filter: (t<'a>, 'a => bool) => t<'a>

    filter(typedArray, predicate) returns a new typed array containing only elements that satisfy predicate.

    See TypedArray.prototype.filter on MDN.

    filterWithIndex

    RESCRIPT
    let filterWithIndex: (t<'a>, ('a, int) => bool) => t<'a>

    filterWithIndex(typedArray, predicate) behaves like filter but also passes the index to predicate.

    find

    RESCRIPT
    let find: (t<'a>, 'a => bool) => option<'a>

    find(typedArray, predicate) returns the first element that satisfies predicate, or None if nothing matches.

    See TypedArray.prototype.find on MDN.

    findWithIndex

    RESCRIPT
    let findWithIndex: (t<'a>, ('a, int) => bool) => option<'a>

    findWithIndex(typedArray, predicate) behaves like find, but predicate also receives the index.

    findLast

    RESCRIPT
    let findLast: (t<'a>, 'a => bool) => option<'a>

    findLast(typedArray, predicate) returns the last element that satisfies predicate.

    See TypedArray.prototype.findLast on MDN.

    findLastWithIndex

    RESCRIPT
    let findLastWithIndex: (t<'a>, ('a, int) => bool) => option<'a>

    findLastWithIndex(typedArray, predicate) is the indexed variant of findLast.

    findIndex

    RESCRIPT
    let findIndex: (t<'a>, 'a => bool) => int

    findIndex(typedArray, predicate) returns the index of the first element that satisfies predicate, or -1 if none do.

    See TypedArray.prototype.findIndex on MDN.

    findIndexWithIndex

    RESCRIPT
    let findIndexWithIndex: (t<'a>, ('a, int) => bool) => int

    findIndexWithIndex(typedArray, predicate) is the indexed variant of findIndex.

    findLastIndex

    RESCRIPT
    let findLastIndex: (t<'a>, 'a => bool) => int

    findLastIndex(typedArray, predicate) returns the index of the last matching element, or -1 if none do.

    See TypedArray.prototype.findLastIndex on MDN.

    findLastIndexWithIndex

    RESCRIPT
    let findLastIndexWithIndex: (t<'a>, ('a, int) => bool) => int

    findLastIndexWithIndex(typedArray, predicate) is the indexed variant of findLastIndex.

    forEach

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

    forEach(typedArray, f) runs f for every element in order.

    See TypedArray.prototype.forEach on MDN.

    forEachWithIndex

    RESCRIPT
    let forEachWithIndex: (t<'a>, ('a, int) => unit) => unit

    forEachWithIndex(typedArray, f) runs f for every element, also providing the index.

    map

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

    map(typedArray, f) returns a new typed array whose elements are produced by applying f to each element.

    See TypedArray.prototype.map on MDN.

    mapWithIndex

    RESCRIPT
    let mapWithIndex: (t<'a>, ('a, int) => 'b) => t<'b>

    mapWithIndex(typedArray, f) behaves like map, but f also receives the index.

    reduce

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

    reduce(typedArray, reducer, initial) combines the elements from left to right using reducer.

    See TypedArray.prototype.reduce on MDN.

    reduceWithIndex

    RESCRIPT
    let reduceWithIndex: (t<'a>, ('b, 'a, int) => 'b, 'b) => 'b

    reduceWithIndex(typedArray, reducer, initial) is the indexed variant of reduce.

    reduceRight

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

    reduceRight(typedArray, reducer, initial) is like reduce but processes the elements from right to left.

    See TypedArray.prototype.reduceRight on MDN.

    reduceRightWithIndex

    RESCRIPT
    let reduceRightWithIndex: (t<'a>, ('b, 'a, int) => 'b, 'b) => 'b

    reduceRightWithIndex(typedArray, reducer, initial) is the indexed variant of reduceRight.

    some

    RESCRIPT
    let some: (t<'a>, 'a => bool) => bool

    some(typedArray, predicate) returns true if predicate returns true for at least one element.

    See TypedArray.prototype.some on MDN.

    someWithIndex

    RESCRIPT
    let someWithIndex: (t<'a>, ('a, int) => bool) => bool

    someWithIndex(typedArray, predicate) behaves like some, but predicate also receives the element index.

    ignore

    RESCRIPT
    let ignore: t<'a> => unit

    ignore(typedArray) ignores the provided typedArray and returns unit.

    This helper is useful when you want to discard a value (for example, the result of an operation with side effects) without having to store or process it further.

    Types and values
    • t
      t
    • v
      get
    • v
      set
    • v
      buffer
    • v
      byteLength
    • v
      byteOffset
    • v
      setArray
    • v
      setArrayFrom
    • v
      length
    • v
      copyAllWithin
    • v
      copyWithinToEnd
      D
    • v
      copyWithin
    • v
      fillAll
    • v
      fillToEnd
      D
    • v
      fill
    • v
      reverse
    • v
      toReversed
    • v
      sort
    • v
      toSorted
    • v
      with
    • v
      includes
    • v
      indexOf
    • v
      indexOfFrom
    • v
      joinWith
    • v
      lastIndexOf
    • v
      lastIndexOfFrom
    • v
      slice
    • v
      sliceToEnd
      D
    • v
      copy
    • v
      subarray
    • v
      subarrayToEnd
      D
    • v
      toString
    • v
      toLocaleString
    • v
      every
    • v
      everyWithIndex
    • v
      filter
    • v
      filterWithIndex
    • v
      find
    • v
      findWithIndex
    • v
      findLast
    • v
      findLastWithIndex
    • v
      findIndex
    • v
      findIndexWithIndex
    • v
      findLastIndex
    • v
      findLastIndexWithIndex
    • v
      forEach
    • v
      forEachWithIndex
    • v
      map
    • v
      mapWithIndex
    • v
      reduce
    • v
      reduceWithIndex
    • v
      reduceRight
    • v
      reduceRightWithIndex
    • v
      some
    • v
      someWithIndex
    • v
      ignore

    © 2025 The ReScript Project

    About
    • Community
    • ReScript Association
    Find us on