@@ -77,12 +77,10 @@ foreign import byteOffset :: forall a. ArrayView a -> ByteOffset
7777-- | Represents the length of this typed array, in bytes.
7878foreign import byteLength :: forall a . ArrayView a -> ByteLength
7979
80- foreign import lengthImpl :: forall a . ArrayView a -> Length
81-
8280-- | Represents the number of elements in this typed array.
8381length :: forall a . ArrayView a -> Length
8482length = lengthImpl
85-
83+ foreign import lengthImpl :: forall a . ArrayView a -> Length
8684
8785-- object creator implementations for each typed array
8886
@@ -99,24 +97,6 @@ foreign import newFloat64Array :: forall a. EffectFn3 a (Nullable ByteOffset) (N
9997
10098-- ----
10199
102- foreign import everyImpl :: forall a b . EffectFn2 (ArrayView a ) (Fn2 b Offset Boolean ) Boolean
103- foreign import someImpl :: forall a b . EffectFn2 (ArrayView a ) (Fn2 b Offset Boolean ) Boolean
104-
105- foreign import fillImpl :: forall a b . EffectFn4 b Offset Offset (ArrayView a ) Unit
106-
107- foreign import mapImpl :: forall a b . EffectFn2 (ArrayView a ) (EffectFn2 b Offset b ) (ArrayView a )
108- foreign import forEachImpl :: forall a b . EffectFn2 (ArrayView a ) (EffectFn2 b Offset Unit ) Unit
109- foreign import filterImpl :: forall a b . EffectFn2 (ArrayView a ) (Fn2 b Offset Boolean ) (ArrayView a )
110- foreign import includesImpl :: forall a b . EffectFn3 (ArrayView a ) b (Nullable Offset ) Boolean
111- foreign import reduceImpl :: forall a b c . EffectFn3 (ArrayView a ) (EffectFn3 c b Offset c ) c c
112- foreign import reduce1Impl :: forall a b . EffectFn2 (ArrayView a ) (EffectFn3 b b Offset b ) b
113- foreign import reduceRightImpl :: forall a b c . EffectFn3 (ArrayView a ) (EffectFn3 c b Offset c ) c c
114- foreign import reduceRight1Impl :: forall a b . EffectFn2 (ArrayView a ) (EffectFn3 b b Offset b ) b
115- foreign import findImpl :: forall a b . EffectFn2 (ArrayView a ) (Fn2 b Offset Boolean ) (Nullable b )
116- foreign import findIndexImpl :: forall a b . EffectFn2 (ArrayView a ) (Fn2 b Offset Boolean ) (Nullable Offset )
117- foreign import indexOfImpl :: forall a b . EffectFn3 (ArrayView a ) b (Nullable Offset ) (Nullable Offset )
118- foreign import lastIndexOfImpl :: forall a b . EffectFn3 (ArrayView a ) b (Nullable Offset ) (Nullable Offset )
119-
120100
121101-- | Value-oriented array offset.
122102type Offset = Int
@@ -177,6 +157,7 @@ fromArray a = runEffectFn3 create a null null
177157-- | Fill the array with a value.
178158fill :: forall a t . TypedArray a t => t -> Offset -> Offset -> ArrayView a -> Effect Unit
179159fill x s e a = runEffectFn4 fillImpl x s e a
160+ foreign import fillImpl :: forall a b . EffectFn4 b Offset Offset (ArrayView a ) Unit
180161
181162-- | Stores multiple values into the typed array.
182163set :: forall a t . TypedArray a t => ArrayView a -> Maybe Offset -> Array t -> Effect Boolean
@@ -199,6 +180,7 @@ mapWithIndex = mapWithIndex' <<< flip
199180
200181mapWithIndex' :: forall a t . TypedArray a t => (t -> Offset -> t ) -> ArrayView a -> ArrayView a
201182mapWithIndex' f a = unsafePerformEffect (runEffectFn2 mapImpl a (mkEffectFn2 (\x o -> pure (f x o))))
183+ foreign import mapImpl :: forall a b . EffectFn2 (ArrayView a ) (EffectFn2 b Offset b ) (ArrayView a )
202184
203185-- | Traverses over each value, returning a new one.
204186traverse :: forall a t . TypedArray a t => (t -> Effect t ) -> ArrayView a -> Effect (ArrayView a )
@@ -221,6 +203,7 @@ traverseWithIndex_ = traverseWithIndex_' <<< flip
221203
222204traverseWithIndex_' :: forall a t . TypedArray a t => (t -> Offset -> Effect Unit ) -> ArrayView a -> Effect Unit
223205traverseWithIndex_' f a = runEffectFn2 forEachImpl a (mkEffectFn2 f)
206+ foreign import forEachImpl :: forall a b . EffectFn2 (ArrayView a ) (EffectFn2 b Offset Unit ) Unit
224207
225208-- | Test a predicate to pass on all values.
226209all :: forall a t . TypedArray a t => (t -> Boolean ) -> ArrayView a -> Effect Boolean
@@ -232,6 +215,7 @@ allWithIndex = every <<< flip
232215
233216every :: forall a t . TypedArray a t => (t -> Offset -> Boolean ) -> ArrayView a -> Effect Boolean
234217every p a = runEffectFn2 everyImpl a (mkFn2 p)
218+ foreign import everyImpl :: forall a b . EffectFn2 (ArrayView a ) (Fn2 b Offset Boolean ) Boolean
235219
236220-- | Test a predicate to pass on any value.
237221any :: forall a t . TypedArray a t => (t -> Boolean ) -> ArrayView a -> Effect Boolean
@@ -243,6 +227,7 @@ anyWithIndex = some <<< flip
243227
244228some :: forall a t . TypedArray a t => (t -> Offset -> Boolean ) -> ArrayView a -> Effect Boolean
245229some p a = runEffectFn2 someImpl a (mkFn2 p)
230+ foreign import someImpl :: forall a b . EffectFn2 (ArrayView a ) (Fn2 b Offset Boolean ) Boolean
246231
247232-- | Returns a new typed array with all values that pass the predicate.
248233filter :: forall a t . TypedArray a t => (t -> Boolean ) -> ArrayView a -> Effect (ArrayView a )
@@ -253,10 +238,12 @@ filterWithIndex = filterWithIndex' <<< flip
253238
254239filterWithIndex' :: forall a t . TypedArray a t => (t -> Offset -> Boolean ) -> ArrayView a -> Effect (ArrayView a )
255240filterWithIndex' p a = runEffectFn2 filterImpl a (mkFn2 p)
241+ foreign import filterImpl :: forall a b . EffectFn2 (ArrayView a ) (Fn2 b Offset Boolean ) (ArrayView a )
256242
257243-- | Tests if a value is an element of the typed array.
258244elem :: forall a t . TypedArray a t => t -> Maybe Offset -> ArrayView a -> Effect Boolean
259245elem x mo a = runEffectFn3 includesImpl a x (toNullable mo)
246+ foreign import includesImpl :: forall a b . EffectFn3 (ArrayView a ) b (Nullable Offset ) Boolean
260247
261248-- | Fetch element at index.
262249unsafeAt :: forall a t . TypedArray a t => Partial => ArrayView a -> Offset -> Effect t
@@ -265,18 +252,22 @@ unsafeAt a o = runEffectFn2 unsafeAtImpl a o
265252-- | Folding from the left.
266253foldlM :: forall a t b . TypedArray a t => (b -> t -> Offset -> Effect b ) -> b -> ArrayView a -> Effect b
267254foldlM f i a = runEffectFn3 reduceImpl a (mkEffectFn3 f) i
255+ foreign import reduceImpl :: forall a b c . EffectFn3 (ArrayView a ) (EffectFn3 c b Offset c ) c c
268256
269257-- | Folding from the left. Assumes the typed array is non-empty.
270258foldl1M :: forall a t . TypedArray a t => (t -> t -> Offset -> Effect t ) -> ArrayView a -> Effect t
271259foldl1M f a = runEffectFn2 reduce1Impl a (mkEffectFn3 f)
260+ foreign import reduce1Impl :: forall a b . EffectFn2 (ArrayView a ) (EffectFn3 b b Offset b ) b
272261
273262-- | Folding from the right.
274263foldrM :: forall a t b . TypedArray a t => (t -> b -> Offset -> Effect b ) -> b -> ArrayView a -> Effect b
275264foldrM f i a = runEffectFn3 reduceRightImpl a (mkEffectFn3 (\acc x o -> f x acc o)) i
265+ foreign import reduceRightImpl :: forall a b c . EffectFn3 (ArrayView a ) (EffectFn3 c b Offset c ) c c
276266
277267-- | Folding from the right. Assumes the typed array is non-empty.
278268foldr1M :: forall a t . TypedArray a t => (t -> t -> Offset -> Effect t ) -> ArrayView a -> Effect t
279269foldr1M f a = runEffectFn2 reduceRight1Impl a (mkEffectFn3 (\acc x o -> f x acc o))
270+ foreign import reduceRight1Impl :: forall a b . EffectFn2 (ArrayView a ) (EffectFn3 b b Offset b ) b
280271
281272-- | Returns the first value satisfying the predicate.
282273find :: forall a t . TypedArray a t => (t -> Boolean ) -> ArrayView a -> Effect (Maybe t )
@@ -287,19 +278,22 @@ findWithIndex = findWithIndex' <<< flip
287278
288279findWithIndex' :: forall a t . TypedArray a t => (t -> Offset -> Boolean ) -> ArrayView a -> Effect (Maybe t )
289280findWithIndex' f a = toMaybe <$> runEffectFn2 findImpl a (mkFn2 f)
281+ foreign import findImpl :: forall a b . EffectFn2 (ArrayView a ) (Fn2 b Offset Boolean ) (Nullable b )
290282
291283-- | Returns the first index of the value satisfying the predicate.
292284findIndex :: forall a t . TypedArray a t => (t -> Offset -> Boolean ) -> ArrayView a -> Effect (Maybe Offset )
293285findIndex f a = toMaybe <$> runEffectFn2 findIndexImpl a (mkFn2 f)
286+ foreign import findIndexImpl :: forall a b . EffectFn2 (ArrayView a ) (Fn2 b Offset Boolean ) (Nullable Offset )
294287
295288-- | Returns the first index of the element, if it exists, from the left.
296289indexOf :: forall a t . TypedArray a t => t -> Maybe Offset -> ArrayView a -> Effect (Maybe Offset )
297290indexOf x mo a = toMaybe <$> runEffectFn3 indexOfImpl a x (toNullable mo)
291+ foreign import indexOfImpl :: forall a b . EffectFn3 (ArrayView a ) b (Nullable Offset ) (Nullable Offset )
298292
299293-- | Returns the first index of the element, if it exists, from the right.
300294lastIndexOf :: forall a t . TypedArray a t => t -> Maybe Offset -> ArrayView a -> Effect (Maybe Offset )
301295lastIndexOf x mo a = toMaybe <$> runEffectFn3 lastIndexOfImpl a x (toNullable mo)
302-
296+ foreign import lastIndexOfImpl :: forall a b . EffectFn3 ( ArrayView a ) b ( Nullable Offset ) ( Nullable Offset )
303297
304298foldl :: forall a b t . TypedArray a t => (b -> t -> b ) -> b -> ArrayView a -> Effect b
305299foldl f = foldlWithIndex' (\a x _ -> f a x)
@@ -331,84 +325,69 @@ foldr1 f = foldr1WithIndex (\_ a x -> f a x)
331325foldr1WithIndex :: forall a t . TypedArray a t => (Offset -> t -> t -> t ) -> ArrayView a -> Effect t
332326foldr1WithIndex f = foldr1M (\x a o -> pure (f o x a))
333327
334- foreign import copyWithinImpl :: forall a . EffectFn4 (ArrayView a ) Offset Offset (Nullable Offset ) Unit
335-
336328-- | Internally copy values - see [MDN's spec](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/copyWithin) for details.
337329copyWithin :: forall a . ArrayView a -> Offset -> Offset -> Maybe Offset -> Effect Unit
338330copyWithin a t s me = runEffectFn4 copyWithinImpl a t s (toNullable me)
339-
340- foreign import reverseImpl :: forall a . EffectFn1 (ArrayView a ) Unit
331+ foreign import copyWithinImpl :: forall a . EffectFn4 (ArrayView a ) Offset Offset (Nullable Offset ) Unit
341332
342333-- | Reverses a typed array in-place.
343334reverse :: forall a . ArrayView a -> Effect Unit
344335reverse a = runEffectFn1 reverseImpl a
336+ foreign import reverseImpl :: forall a . EffectFn1 (ArrayView a ) Unit
345337
346- foreign import setImpl :: forall a b . EffectFn3 (ArrayView a ) Offset b Unit
347338
348339setInternal :: forall a b . (b -> Length ) -> ArrayView a -> Maybe Offset -> b -> Effect Boolean
349340setInternal lenfn a mo b =
350341 let o = fromMaybe 0 mo
351342 in if o >= 0 && lenfn b <= length a - o
352343 then runEffectFn3 setImpl a o b *> pure true
353344 else pure false
345+ foreign import setImpl :: forall a b . EffectFn3 (ArrayView a ) Offset b Unit
346+
354347
355348
356349-- | Stores multiple values in the typed array, reading input values from the second typed array.
357350setTyped :: forall a . ArrayView a -> Maybe Offset -> ArrayView a -> Effect Boolean
358351setTyped = setInternal length
359352
360-
361- -- | Copy the entire contents of the typed array into a new buffer.
362- foreign import sliceImpl :: forall a . EffectFn3 (ArrayView a ) Offset Offset (ArrayView a )
363-
364353-- | Copy part of the contents of a typed array into a new buffer, between some start and end indices.
365354slice :: forall a . Offset -> Offset -> ArrayView a -> Effect (ArrayView a )
366355slice s e a = runEffectFn3 sliceImpl a s e
367-
368- foreign import sortImpl :: forall a . EffectFn1 (ArrayView a ) Unit
356+ foreign import sliceImpl :: forall a . EffectFn3 (ArrayView a ) Offset Offset (ArrayView a )
369357
370358-- | Sorts the values in-place.
371359sort :: forall a . ArrayView a -> Effect Unit
372360sort a = runEffectFn1 sortImpl a
373-
374-
375- foreign import subArrayImpl :: forall a . Fn3 (ArrayView a ) Offset Offset (ArrayView a )
361+ foreign import sortImpl :: forall a . EffectFn1 (ArrayView a ) Unit
376362
377363-- | Returns a new typed array view of the same buffer, beginning at the index and ending at the second.
378364subArray :: forall a . Offset -> Offset -> ArrayView a -> ArrayView a
379365subArray s e a = runFn3 subArrayImpl a s e
380-
381- foreign import toStringImpl :: forall a . EffectFn1 (ArrayView a ) String
366+ foreign import subArrayImpl :: forall a . Fn3 (ArrayView a ) Offset Offset (ArrayView a )
382367
383368-- | 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.
384369toString :: forall a . ArrayView a -> Effect String
385370toString a = runEffectFn1 toStringImpl a
386-
387- foreign import joinImpl :: forall a . EffectFn2 (ArrayView a ) String String
371+ foreign import toStringImpl :: forall a . EffectFn1 (ArrayView a ) String
388372
389373-- | Prints array to a delimiter-separated string - see [MDN's spec](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/join) for details.
390374join :: forall a . String -> ArrayView a -> Effect String
391375join s a = runEffectFn2 joinImpl a s
392-
393-
394- foreign import hasIndexImpl :: forall a . Fn2 (ArrayView a ) Offset Boolean
376+ foreign import joinImpl :: forall a . EffectFn2 (ArrayView a ) String String
395377
396378-- | Determine if a certain index is valid.
397379hasIndex :: forall a . ArrayView a -> Offset -> Boolean
398380hasIndex a o = runFn2 hasIndexImpl a o
399-
400-
401- foreign import unsafeAtImpl :: forall a b . EffectFn2 (ArrayView a ) Offset b
381+ foreign import hasIndexImpl :: forall a . Fn2 (ArrayView a ) Offset Boolean
402382
403383-- | Fetch element at index.
404384at :: forall a t . TypedArray a t => ArrayView a -> Offset -> Effect (Maybe t )
405385at a n = toMaybe <$> runEffectFn2 unsafeAtImpl a n
386+ foreign import unsafeAtImpl :: forall a b . EffectFn2 (ArrayView a ) Offset b
406387
407388infixl 3 at as !
408389
409-
410- foreign import toArrayImpl :: forall a b . EffectFn1 (ArrayView a ) (Array b )
411-
412390-- | Turn typed array into an array.
413391toArray :: forall a t . TypedArray a t => ArrayView a -> Effect (Array t )
414392toArray a = runEffectFn1 toArrayImpl a
393+ foreign import toArrayImpl :: forall a b . EffectFn1 (ArrayView a ) (Array b )
0 commit comments