TypedArray

buffer

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

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

See TypedArray.prototype.buffer on MDN.

byteLength

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

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

See TypedArray.prototype.byteLength on MDN.

Examples

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

byteOffset

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

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

See TypedArray.prototype.byteOffset on MDN.

copy

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

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

copyAllWithin

RES
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

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

copyWithin

RES
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

RES
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"

copyWithinToEnd

Deprecated

RES
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

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

every

RES
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

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

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

fill

RES
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

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

fillAll

RES
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

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

fillToEnd

Deprecated

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

filter

RES
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

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

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

find

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

findIndex

RES
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

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

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

findLast

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

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

See TypedArray.prototype.findLast on MDN.

findLastIndex

RES
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

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

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

findLastWithIndex

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

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

findWithIndex

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

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

forEach

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

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

See TypedArray.prototype.forEach on MDN.

forEachWithIndex

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

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

get

RES
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

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

ignore

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

includes

RES
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

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

indexOf

RES
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

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

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

joinWith

RES
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

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

lastIndexOf

RES
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

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

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

length

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

length(typedArray) returns the number of elements.

See TypedArray.prototype.length on MDN.

Examples

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

map

RES
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

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

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

reduce

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

reduceRight

RES
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

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

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

reduceWithIndex

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

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

reverse

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

set

RES
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

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

setArray

RES
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

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

setArrayFrom

RES
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

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

slice

RES
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

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

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

some

RES
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

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

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

sort

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

subarray

RES
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

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

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

t

RES
type t<'a>

toLocaleString

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

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

See TypedArray.prototype.toLocaleString on MDN.

toReversed

RES
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

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

toSorted

RES
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

RES
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"

toString

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

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

See TypedArray.prototype.toString on MDN.

Examples

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

with

RES
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

RES
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"