TypedArray

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.

copy

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

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

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"

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"

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"

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.

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"

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.

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.

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.

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.

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.

findLastWithIndex

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

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

findWithIndex

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

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

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.

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

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.

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.

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

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.

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.

reduceWithIndex

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

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

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.

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)

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"

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.

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.

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.

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.

t

RESCRIPT
type t<'a>

toLocaleString

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

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

See TypedArray.prototype.toLocaleString 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"

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"

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"

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"