Module

Data.ArrayBuffer.Typed

Package
purescript-arraybuffer
Repository
purescript-contrib/purescript-arraybuffer

This module represents the functional bindings to JavaScript's TypedArray and other objects. See MDN's spec for details.

Creation

  • whole, remainder, and part are functions for building a typed array accessible interface on top of an existing ArrayBuffer
  • empty and fromArray are functions for creating pure typed arrays

Modification

  • fill, set, and setTyped are functions for assigning values from external sources
  • map and traverse allow you to create a new array from the existing values in another
  • copyWithin allows you to set values to the array that exist in other parts of the array
  • filter creates a new array without the values that don't pass a predicate
  • reverse modifies an existing array in-place, with all values reversed
  • sort modifies an existing array in-place, with all values sorted

Access

  • elem, all, and any are functions for testing the contents of an array
  • unsafeAt, hasIndex, and at are used to get values from an array, with an index
  • foldr, foldrM, foldr1, foldr1M, foldl, foldlM, foldl1, foldl1M all can reduce an array
  • find and findIndex are searching functions via a predicate
  • indexOf and lastIndexOf are searching functions via equality
  • slice returns a new typed array with a new copied underlying ArrayBuffer
  • subArray returns a new typed array view of the same ArrayBuffer
  • toString prints to a CSV, join allows you to supply the delimiter
  • toArray returns an array of numeric values

#Index Source

type Index = Int

Value-oriented array index.

#Length Source

type Length = Int

Value-oriented array length.

#buffer Source

buffer :: forall a. ArrayView a -> ArrayBuffer

ArrayBuffer being mapped by the typed array.

#byteOffset Source

byteOffset :: forall a. ArrayView a -> ByteOffset

Represents the offset of this view from the start of its ArrayBuffer.

#byteLength Source

byteLength :: forall a. ArrayView a -> ByteLength

Represents the length of this typed array, in bytes.

#length Source

length :: forall a. ArrayView a -> Length

Represents the number of elements in this typed array.

#compare Source

compare :: forall a t. TypedArray a t => Ord t => ArrayView a -> ArrayView a -> Effect Ordering

Compare 2 typed arrays.

#eq Source

eq :: forall a t. TypedArray a t => Eq t => ArrayView a -> ArrayView a -> Effect Boolean

Equality test for typed arrays.

#whole Source

whole :: forall a t. TypedArray a t => ArrayBuffer -> Effect (ArrayView a)

View mapping the whole ArrayBuffer.

#remainder Source

remainder :: forall a b t. TypedArray a t => BytesPerType b => ArrayBuffer -> Index -> Effect (ArrayView a)

View mapping the rest of an ArrayBuffer after an index.

#part Source

part :: forall a t. TypedArray a t => BytesPerType a => ArrayBuffer -> Index -> Length -> Effect (ArrayView a)

View mapping a region of the ArrayBuffer.

#empty Source

empty :: forall a t. TypedArray a t => Length -> Effect (ArrayView a)

Creates an empty typed array, where each value is assigned 0.

#fromArray Source

fromArray :: forall a t. TypedArray a t => Array t -> Effect (ArrayView a)

Creates a typed array from an input array of values, to be binary serialized.

#fill Source

fill :: forall a t. TypedArray a t => t -> Index -> Index -> ArrayView a -> Effect Unit

Fill the array with a value.

#set Source

set :: forall a t. TypedArray a t => ArrayView a -> Maybe Index -> Array t -> Effect Boolean

Stores multiple values into the typed array.

#setTyped Source

setTyped :: forall a. ArrayView a -> Maybe Index -> ArrayView a -> Effect Boolean

Stores multiple values in the typed array, reading input values from the second typed array.

#copyWithin Source

copyWithin :: forall a. ArrayView a -> Index -> Index -> Maybe Index -> Effect Unit

Internally copy values - see MDN's spec for details.

#map Source

map :: forall a t. TypedArray a t => (t -> t) -> ArrayView a -> ArrayView a

Maps a new value over the typed array, creating a new ArrayBuffer and typed array as well.

#traverse Source

traverse :: forall a t. TypedArray a t => (t -> Effect t) -> ArrayView a -> Effect (ArrayView a)

Traverses over each value, returning a new one.

#traverse_ Source

traverse_ :: forall a t. TypedArray a t => (t -> Effect Unit) -> ArrayView a -> Effect Unit

Traverses over each value.

#filter Source

filter :: forall a t. TypedArray a t => (t -> Boolean) -> ArrayView a -> Effect (ArrayView a)

Returns a new typed array with all values that pass the predicate.

#mapWithIndex Source

mapWithIndex :: forall a t. TypedArray a t => (Index -> t -> t) -> ArrayView a -> ArrayView a

Apply a function to each element in an array, supplying a generated zero-based index integer along with the element, creating a typed array with the new elements.

#traverseWithIndex Source

traverseWithIndex :: forall a t. TypedArray a t => (Index -> t -> Effect t) -> ArrayView a -> Effect (ArrayView a)

Traverses over each value, returning a new one.

#traverseWithIndex_ Source

traverseWithIndex_ :: forall a t. TypedArray a t => (Index -> t -> Effect Unit) -> ArrayView a -> Effect Unit

Traverses over each value.

#filterWithIndex Source

filterWithIndex :: forall a t. TypedArray a t => (Index -> t -> Boolean) -> ArrayView a -> Effect (ArrayView a)

Returns a new typed array with all values that pass the predicate. The predicate function receives the index and the element.

#sort Source

sort :: forall a. ArrayView a -> Effect Unit

Sorts the values in-place.

#reverse Source

reverse :: forall a. ArrayView a -> Effect Unit

Reverses a typed array in-place.

#elem Source

elem :: forall a t. TypedArray a t => t -> Maybe Index -> ArrayView a -> Effect Boolean

Tests if a value is an element of the typed array.

#all Source

all :: forall a t. TypedArray a t => (t -> Boolean) -> ArrayView a -> Effect Boolean

Test a predicate to pass on all values.

#any Source

any :: forall a t. TypedArray a t => (t -> Boolean) -> ArrayView a -> Effect Boolean

Test a predicate to pass on any value.

#allWithIndex Source

allWithIndex :: forall a t. TypedArray a t => (Index -> t -> Boolean) -> ArrayView a -> Effect Boolean

Test a predicate to pass on all values. The predicate function receives the index and the element.

#anyWithIndex Source

anyWithIndex :: forall a t. TypedArray a t => (Index -> t -> Boolean) -> ArrayView a -> Effect Boolean

Test a predicate (that receives also an index) to pass on any value.

#unsafeAt Source

unsafeAt :: forall a t. TypedArray a t => Partial => ArrayView a -> Index -> Effect t

Fetch element at index.

#hasIndex Source

hasIndex :: forall a. ArrayView a -> Index -> Boolean

Determine if a certain index is valid.

#at Source

at :: forall a t. TypedArray a t => ArrayView a -> Index -> Effect (Maybe t)

Fetch element at index.

#(!) Source

Operator alias for Data.ArrayBuffer.Typed.at (left-associative / precedence 3)

#reduce Source

reduce :: forall a t b. TypedArray a t => (b -> t -> Index -> Effect b) -> b -> ArrayView a -> Effect b

Folding from the left.

#reduce1 Source

reduce1 :: forall a t. Partial => TypedArray a t => (t -> t -> Index -> Effect t) -> ArrayView a -> Effect t

Folding from the left. Assumes the typed array is non-empty.

#foldl Source

foldl :: forall a b t. TypedArray a t => (b -> t -> b) -> b -> ArrayView a -> Effect b

Fold a list from the left, accumulating the result using the specified function.

#foldl1 Source

foldl1 :: forall a t. Partial => TypedArray a t => (t -> t -> t) -> ArrayView a -> Effect t

Folding from the left. Assumes the typed array is non-empty.

#reduceRight Source

reduceRight :: forall a t b. TypedArray a t => (t -> b -> Index -> Effect b) -> b -> ArrayView a -> Effect b

Folding from the right.

#reduceRight1 Source

reduceRight1 :: forall a t. Partial => TypedArray a t => (t -> t -> Index -> Effect t) -> ArrayView a -> Effect t

Folding from the right. Assumes the typed array is non-empty.

#foldr Source

foldr :: forall a b t. TypedArray a t => (t -> b -> b) -> b -> ArrayView a -> Effect b

Fold a list from the right, accumulating the result using the specified function.

#foldr1 Source

foldr1 :: forall a t. Partial => TypedArray a t => (t -> t -> t) -> ArrayView a -> Effect t

Folding from the right. Assumes the typed array is non-empty.

#foldlWithIndex Source

foldlWithIndex :: forall a b t. TypedArray a t => (Index -> b -> t -> b) -> b -> ArrayView a -> Effect b

Fold a list from the left, accumulating the result using the supplied function. The accumulating function receives the index, the accumulated value and the element.

#foldrWithIndex Source

foldrWithIndex :: forall a b t. TypedArray a t => (Index -> t -> b -> b) -> b -> ArrayView a -> Effect b

Fold a list from the right, accumulating the result using the supplied function. The accumulating function receives the index, the element and the accumulated value.

#find Source

find :: forall a t. TypedArray a t => (t -> Boolean) -> ArrayView a -> Effect (Maybe t)

Returns the first value satisfying the predicate.

#findIndex Source

findIndex :: forall a t. TypedArray a t => (t -> Index -> Boolean) -> ArrayView a -> Effect (Maybe Index)

Returns the first index of the value satisfying the predicate.

#findWithIndex Source

findWithIndex :: forall a t. TypedArray a t => (Index -> t -> Boolean) -> ArrayView a -> Effect (Maybe t)

Returns the first value satisfying the predicate. The predicate receives the index and the element at that index.

#indexOf Source

indexOf :: forall a t. TypedArray a t => t -> Maybe Index -> ArrayView a -> Effect (Maybe Index)

Returns the first index of the element, if it exists, from the left.

#lastIndexOf Source

lastIndexOf :: forall a t. TypedArray a t => t -> Maybe Index -> ArrayView a -> Effect (Maybe Index)

Returns the first index of the element, if it exists, from the right.

#slice Source

slice :: forall a. Index -> Index -> ArrayView a -> Effect (ArrayView a)

Copy part of the contents of a typed array into a new ArrayBuffer, between the start and end indices.

#subArray Source

subArray :: forall a. Index -> Index -> ArrayView a -> ArrayView a

Returns a new typed array view of the same ArrayBuffer, beginning at the index and ending at the second.

#toString Source

toString :: forall a. ArrayView a -> Effect String

Prints array to a comma-separated string - see MDN's spec for details.

#join Source

join :: forall a. String -> ArrayView a -> Effect String

Prints array to a delimiter-separated string - see MDN's spec for details.

#toArray Source

toArray :: forall a t. TypedArray a t => ArrayView a -> Effect (Array t)

Turn typed array into an array.