3
3
4
4
module Data.ArrayBuffer.Typed
5
5
( polyFill
6
- , Offset , Length , Range
6
+ , Offset , Length
7
7
, buffer , byteOffset , byteLength , length
8
8
, class TypedArray
9
9
, create , whole , remainder , part , empty , fromArray
@@ -28,7 +28,6 @@ import Data.Float32 (Float32) as F
28
28
import Data.Function.Uncurried (Fn2 , Fn3 , mkFn2 , runFn2 , runFn3 )
29
29
import Data.Maybe (Maybe (..), fromMaybe )
30
30
import Data.Nullable (Nullable , notNull , null , toMaybe , toNullable )
31
- import Data.Tuple (Tuple (..))
32
31
import Data.Typelevel.Num (class Nat , toInt' )
33
32
import Data.UInt (UInt )
34
33
import Effect (Effect )
@@ -75,7 +74,7 @@ foreign import newFloat64Array :: forall a. EffectFn3 a (Nullable ByteOffset) (N
75
74
foreign import everyImpl :: forall a b . Fn2 (ArrayView a ) (Fn2 b Offset Boolean ) Boolean
76
75
foreign import someImpl :: forall a b . Fn2 (ArrayView a ) (Fn2 b Offset Boolean ) Boolean
77
76
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
79
78
80
79
foreign import mapImpl :: forall a b . EffectFn2 (ArrayView a ) (EffectFn2 b Offset b ) (ArrayView a )
81
80
foreign import forEachImpl :: forall a b . EffectFn2 (ArrayView a ) (EffectFn2 b Offset Unit ) Unit
@@ -96,10 +95,6 @@ type Offset = Int
96
95
-- | Value-oriented array length
97
96
type Length = Int
98
97
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
-
103
98
104
99
-- TODO use purescript-quotient
105
100
-- | 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)
184
179
fromArray a = runEffectFn3 create a null null
185
180
186
181
-- | 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
191
184
192
185
-- | Stores multiple values into the typed array
193
186
set :: forall a t . TypedArray a t => ArrayView a -> Maybe Offset -> Array t -> Effect Boolean
@@ -367,13 +360,11 @@ setTyped = setInternal length
367
360
368
361
369
362
-- | 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 )
371
364
372
365
-- | 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
377
368
378
369
foreign import sortImpl :: forall a . EffectFn1 (ArrayView a ) Unit
379
370
@@ -382,7 +373,7 @@ sort :: forall a. ArrayView a -> Effect Unit
382
373
sort a = runEffectFn1 sortImpl a
383
374
384
375
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 )
386
377
387
378
-- | Returns a new typed array view of the same buffer, beginning at the index and ending at the second.
388
379
-- |
@@ -391,10 +382,8 @@ foreign import subArrayImpl :: forall a. Fn3 (ArrayView a) (Nullable Offset) (Nu
391
382
-- | mutable replica of the original array - the sub-array reference reflects mutations to the original array.
392
383
-- | However, when the sub-array is is actually a smaller contiguous portion of the array, then it behaves
393
384
-- | 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
398
387
399
388
-- | 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.
400
389
foreign import toString :: forall a . ArrayView a -> String
0 commit comments