33
44module Data.ArrayBuffer.Typed
55 ( polyFill
6- , Offset , Length , Range
6+ , Offset , Length
77 , buffer , byteOffset , byteLength , length
88 , class TypedArray
99 , create , whole , remainder , part , empty , fromArray
@@ -28,7 +28,6 @@ import Data.Float32 (Float32) as F
2828import Data.Function.Uncurried (Fn2 , Fn3 , mkFn2 , runFn2 , runFn3 )
2929import Data.Maybe (Maybe (..), fromMaybe )
3030import Data.Nullable (Nullable , notNull , null , toMaybe , toNullable )
31- import Data.Tuple (Tuple (..))
3231import Data.Typelevel.Num (class Nat , toInt' )
3332import Data.UInt (UInt )
3433import Effect (Effect )
@@ -75,7 +74,7 @@ foreign import newFloat64Array :: forall a. EffectFn3 a (Nullable ByteOffset) (N
7574foreign import everyImpl :: forall a b . Fn2 (ArrayView a ) (Fn2 b Offset Boolean ) Boolean
7675foreign import someImpl :: forall a b . Fn2 (ArrayView a ) (Fn2 b Offset Boolean ) Boolean
7776
78- foreign import fillImpl :: forall a b . EffectFn4 (ArrayView a ) b ( Nullable Offset ) ( Nullable Offset ) Unit
77+ foreign import fillImpl :: forall a b . EffectFn4 (ArrayView a ) b Offset Offset Unit
7978
8079foreign import mapImpl :: forall a b . EffectFn2 (ArrayView a ) (EffectFn2 b Offset b ) (ArrayView a )
8180foreign import forEachImpl :: forall a b . EffectFn2 (ArrayView a ) (EffectFn2 b Offset Unit ) Unit
@@ -96,10 +95,6 @@ type Offset = Int
9695-- | Value-oriented array length
9796type Length = Int
9897
99- -- | Represents a range of indices, where if omitted, it represents the whole span.
100- -- | If only the second argument is omitted, then it represents the remainder of the span after the first index.
101- type Range = Maybe (Tuple Offset (Maybe Offset ))
102-
10398
10499-- TODO use purescript-quotient
105100-- | Typeclass that associates a measured user-level type with a typed array.
@@ -184,10 +179,8 @@ fromArray :: forall a t. TypedArray a t => Array t -> Effect (ArrayView a)
184179fromArray a = runEffectFn3 create a null null
185180
186181-- | Fill the array with a value
187- fill :: forall a t . TypedArray a t => ArrayView a -> t -> Range -> Effect Unit
188- fill a x mz = case mz of
189- Nothing -> runEffectFn4 fillImpl a x null null
190- Just (Tuple s me) -> runEffectFn4 fillImpl a x (notNull s) (toNullable me)
182+ fill :: forall a t . TypedArray a t => t -> Offset -> Offset -> ArrayView a -> Effect Unit
183+ fill x s e a = runEffectFn4 fillImpl a x s e
191184
192185-- | Stores multiple values into the typed array
193186set :: forall a t . TypedArray a t => ArrayView a -> Maybe Offset -> Array t -> Effect Boolean
@@ -367,13 +360,11 @@ setTyped = setInternal length
367360
368361
369362-- | Copy the entire contents of the typed array into a new buffer.
370- foreign import sliceImpl :: forall a . EffectFn3 (ArrayView a ) ( Nullable Offset ) ( Nullable Offset ) (ArrayView a )
363+ foreign import sliceImpl :: forall a . EffectFn3 (ArrayView a ) Offset Offset (ArrayView a )
371364
372365-- | Copy part of the contents of a typed array into a new buffer, between some start and end indices.
373- slice :: forall a . ArrayView a -> Range -> Effect (ArrayView a )
374- slice a mz = case mz of
375- Nothing -> runEffectFn3 sliceImpl a null null
376- Just (Tuple s me) -> runEffectFn3 sliceImpl a (notNull s) (toNullable me)
366+ slice :: forall a . Offset -> Offset -> ArrayView a -> Effect (ArrayView a )
367+ slice s e a = runEffectFn3 sliceImpl a s e
377368
378369foreign import sortImpl :: forall a . EffectFn1 (ArrayView a ) Unit
379370
@@ -382,7 +373,7 @@ sort :: forall a. ArrayView a -> Effect Unit
382373sort a = runEffectFn1 sortImpl a
383374
384375
385- foreign import subArrayImpl :: forall a . Fn3 (ArrayView a ) ( Nullable Offset ) ( Nullable Offset ) (ArrayView a )
376+ foreign import subArrayImpl :: forall a . Fn3 (ArrayView a ) Offset Offset (ArrayView a )
386377
387378-- | Returns a new typed array view of the same buffer, beginning at the index and ending at the second.
388379-- |
@@ -391,10 +382,8 @@ foreign import subArrayImpl :: forall a. Fn3 (ArrayView a) (Nullable Offset) (Nu
391382-- | mutable replica of the original array - the sub-array reference reflects mutations to the original array.
392383-- | However, when the sub-array is is actually a smaller contiguous portion of the array, then it behaves
393384-- | purely, because JavaScript interally calls `Data.ArrayBuffer.ArrayBuffer.slice`.
394- subArray :: forall a . ArrayView a -> Range -> ArrayView a
395- subArray a mz = case mz of
396- Nothing -> runFn3 subArrayImpl a null null
397- Just (Tuple s me) -> runFn3 subArrayImpl a (notNull s) (toNullable me)
385+ subArray :: forall a . Offset -> Offset -> ArrayView a -> ArrayView a
386+ subArray s e a = runFn3 subArrayImpl a s e
398387
399388-- | Prints array to a comma-separated string - see [MDN's spec](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/toString) for details.
400389foreign import toString :: forall a . ArrayView a -> String
0 commit comments