@@ -77,12 +77,10 @@ foreign import byteOffset :: forall a. ArrayView a -> ByteOffset
77
77
-- | Represents the length of this typed array, in bytes.
78
78
foreign import byteLength :: forall a . ArrayView a -> ByteLength
79
79
80
- foreign import lengthImpl :: forall a . ArrayView a -> Length
81
-
82
80
-- | Represents the number of elements in this typed array.
83
81
length :: forall a . ArrayView a -> Length
84
82
length = lengthImpl
85
-
83
+ foreign import lengthImpl :: forall a . ArrayView a -> Length
86
84
87
85
-- object creator implementations for each typed array
88
86
@@ -99,24 +97,6 @@ foreign import newFloat64Array :: forall a. EffectFn3 a (Nullable ByteOffset) (N
99
97
100
98
-- ----
101
99
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
-
120
100
121
101
-- | Value-oriented array offset.
122
102
type Offset = Int
@@ -177,6 +157,7 @@ fromArray a = runEffectFn3 create a null null
177
157
-- | Fill the array with a value.
178
158
fill :: forall a t . TypedArray a t => t -> Offset -> Offset -> ArrayView a -> Effect Unit
179
159
fill x s e a = runEffectFn4 fillImpl x s e a
160
+ foreign import fillImpl :: forall a b . EffectFn4 b Offset Offset (ArrayView a ) Unit
180
161
181
162
-- | Stores multiple values into the typed array.
182
163
set :: forall a t . TypedArray a t => ArrayView a -> Maybe Offset -> Array t -> Effect Boolean
@@ -199,6 +180,7 @@ mapWithIndex = mapWithIndex' <<< flip
199
180
200
181
mapWithIndex' :: forall a t . TypedArray a t => (t -> Offset -> t ) -> ArrayView a -> ArrayView a
201
182
mapWithIndex' 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 )
202
184
203
185
-- | Traverses over each value, returning a new one.
204
186
traverse :: forall a t . TypedArray a t => (t -> Effect t ) -> ArrayView a -> Effect (ArrayView a )
@@ -221,6 +203,7 @@ traverseWithIndex_ = traverseWithIndex_' <<< flip
221
203
222
204
traverseWithIndex_' :: forall a t . TypedArray a t => (t -> Offset -> Effect Unit ) -> ArrayView a -> Effect Unit
223
205
traverseWithIndex_' f a = runEffectFn2 forEachImpl a (mkEffectFn2 f)
206
+ foreign import forEachImpl :: forall a b . EffectFn2 (ArrayView a ) (EffectFn2 b Offset Unit ) Unit
224
207
225
208
-- | Test a predicate to pass on all values.
226
209
all :: forall a t . TypedArray a t => (t -> Boolean ) -> ArrayView a -> Effect Boolean
@@ -232,6 +215,7 @@ allWithIndex = every <<< flip
232
215
233
216
every :: forall a t . TypedArray a t => (t -> Offset -> Boolean ) -> ArrayView a -> Effect Boolean
234
217
every p a = runEffectFn2 everyImpl a (mkFn2 p)
218
+ foreign import everyImpl :: forall a b . EffectFn2 (ArrayView a ) (Fn2 b Offset Boolean ) Boolean
235
219
236
220
-- | Test a predicate to pass on any value.
237
221
any :: forall a t . TypedArray a t => (t -> Boolean ) -> ArrayView a -> Effect Boolean
@@ -243,6 +227,7 @@ anyWithIndex = some <<< flip
243
227
244
228
some :: forall a t . TypedArray a t => (t -> Offset -> Boolean ) -> ArrayView a -> Effect Boolean
245
229
some p a = runEffectFn2 someImpl a (mkFn2 p)
230
+ foreign import someImpl :: forall a b . EffectFn2 (ArrayView a ) (Fn2 b Offset Boolean ) Boolean
246
231
247
232
-- | Returns a new typed array with all values that pass the predicate.
248
233
filter :: forall a t . TypedArray a t => (t -> Boolean ) -> ArrayView a -> Effect (ArrayView a )
@@ -253,10 +238,12 @@ filterWithIndex = filterWithIndex' <<< flip
253
238
254
239
filterWithIndex' :: forall a t . TypedArray a t => (t -> Offset -> Boolean ) -> ArrayView a -> Effect (ArrayView a )
255
240
filterWithIndex' p a = runEffectFn2 filterImpl a (mkFn2 p)
241
+ foreign import filterImpl :: forall a b . EffectFn2 (ArrayView a ) (Fn2 b Offset Boolean ) (ArrayView a )
256
242
257
243
-- | Tests if a value is an element of the typed array.
258
244
elem :: forall a t . TypedArray a t => t -> Maybe Offset -> ArrayView a -> Effect Boolean
259
245
elem x mo a = runEffectFn3 includesImpl a x (toNullable mo)
246
+ foreign import includesImpl :: forall a b . EffectFn3 (ArrayView a ) b (Nullable Offset ) Boolean
260
247
261
248
-- | Fetch element at index.
262
249
unsafeAt :: forall a t . TypedArray a t => Partial => ArrayView a -> Offset -> Effect t
@@ -265,18 +252,22 @@ unsafeAt a o = runEffectFn2 unsafeAtImpl a o
265
252
-- | Folding from the left.
266
253
foldlM :: forall a t b . TypedArray a t => (b -> t -> Offset -> Effect b ) -> b -> ArrayView a -> Effect b
267
254
foldlM 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
268
256
269
257
-- | Folding from the left. Assumes the typed array is non-empty.
270
258
foldl1M :: forall a t . TypedArray a t => (t -> t -> Offset -> Effect t ) -> ArrayView a -> Effect t
271
259
foldl1M f a = runEffectFn2 reduce1Impl a (mkEffectFn3 f)
260
+ foreign import reduce1Impl :: forall a b . EffectFn2 (ArrayView a ) (EffectFn3 b b Offset b ) b
272
261
273
262
-- | Folding from the right.
274
263
foldrM :: forall a t b . TypedArray a t => (t -> b -> Offset -> Effect b ) -> b -> ArrayView a -> Effect b
275
264
foldrM 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
276
266
277
267
-- | Folding from the right. Assumes the typed array is non-empty.
278
268
foldr1M :: forall a t . TypedArray a t => (t -> t -> Offset -> Effect t ) -> ArrayView a -> Effect t
279
269
foldr1M 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
280
271
281
272
-- | Returns the first value satisfying the predicate.
282
273
find :: forall a t . TypedArray a t => (t -> Boolean ) -> ArrayView a -> Effect (Maybe t )
@@ -287,19 +278,22 @@ findWithIndex = findWithIndex' <<< flip
287
278
288
279
findWithIndex' :: forall a t . TypedArray a t => (t -> Offset -> Boolean ) -> ArrayView a -> Effect (Maybe t )
289
280
findWithIndex' f a = toMaybe <$> runEffectFn2 findImpl a (mkFn2 f)
281
+ foreign import findImpl :: forall a b . EffectFn2 (ArrayView a ) (Fn2 b Offset Boolean ) (Nullable b )
290
282
291
283
-- | Returns the first index of the value satisfying the predicate.
292
284
findIndex :: forall a t . TypedArray a t => (t -> Offset -> Boolean ) -> ArrayView a -> Effect (Maybe Offset )
293
285
findIndex f a = toMaybe <$> runEffectFn2 findIndexImpl a (mkFn2 f)
286
+ foreign import findIndexImpl :: forall a b . EffectFn2 (ArrayView a ) (Fn2 b Offset Boolean ) (Nullable Offset )
294
287
295
288
-- | Returns the first index of the element, if it exists, from the left.
296
289
indexOf :: forall a t . TypedArray a t => t -> Maybe Offset -> ArrayView a -> Effect (Maybe Offset )
297
290
indexOf 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 )
298
292
299
293
-- | Returns the first index of the element, if it exists, from the right.
300
294
lastIndexOf :: forall a t . TypedArray a t => t -> Maybe Offset -> ArrayView a -> Effect (Maybe Offset )
301
295
lastIndexOf 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 )
303
297
304
298
foldl :: forall a b t . TypedArray a t => (b -> t -> b ) -> b -> ArrayView a -> Effect b
305
299
foldl f = foldlWithIndex' (\a x _ -> f a x)
@@ -331,84 +325,69 @@ foldr1 f = foldr1WithIndex (\_ a x -> f a x)
331
325
foldr1WithIndex :: forall a t . TypedArray a t => (Offset -> t -> t -> t ) -> ArrayView a -> Effect t
332
326
foldr1WithIndex f = foldr1M (\x a o -> pure (f o x a))
333
327
334
- foreign import copyWithinImpl :: forall a . EffectFn4 (ArrayView a ) Offset Offset (Nullable Offset ) Unit
335
-
336
328
-- | Internally copy values - see [MDN's spec](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/copyWithin) for details.
337
329
copyWithin :: forall a . ArrayView a -> Offset -> Offset -> Maybe Offset -> Effect Unit
338
330
copyWithin 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
341
332
342
333
-- | Reverses a typed array in-place.
343
334
reverse :: forall a . ArrayView a -> Effect Unit
344
335
reverse a = runEffectFn1 reverseImpl a
336
+ foreign import reverseImpl :: forall a . EffectFn1 (ArrayView a ) Unit
345
337
346
- foreign import setImpl :: forall a b . EffectFn3 (ArrayView a ) Offset b Unit
347
338
348
339
setInternal :: forall a b . (b -> Length ) -> ArrayView a -> Maybe Offset -> b -> Effect Boolean
349
340
setInternal lenfn a mo b =
350
341
let o = fromMaybe 0 mo
351
342
in if o >= 0 && lenfn b <= length a - o
352
343
then runEffectFn3 setImpl a o b *> pure true
353
344
else pure false
345
+ foreign import setImpl :: forall a b . EffectFn3 (ArrayView a ) Offset b Unit
346
+
354
347
355
348
356
349
-- | Stores multiple values in the typed array, reading input values from the second typed array.
357
350
setTyped :: forall a . ArrayView a -> Maybe Offset -> ArrayView a -> Effect Boolean
358
351
setTyped = setInternal length
359
352
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
-
364
353
-- | Copy part of the contents of a typed array into a new buffer, between some start and end indices.
365
354
slice :: forall a . Offset -> Offset -> ArrayView a -> Effect (ArrayView a )
366
355
slice 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 )
369
357
370
358
-- | Sorts the values in-place.
371
359
sort :: forall a . ArrayView a -> Effect Unit
372
360
sort 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
376
362
377
363
-- | Returns a new typed array view of the same buffer, beginning at the index and ending at the second.
378
364
subArray :: forall a . Offset -> Offset -> ArrayView a -> ArrayView a
379
365
subArray 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 )
382
367
383
368
-- | 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.
384
369
toString :: forall a . ArrayView a -> Effect String
385
370
toString 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
388
372
389
373
-- | 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.
390
374
join :: forall a . String -> ArrayView a -> Effect String
391
375
join 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
395
377
396
378
-- | Determine if a certain index is valid.
397
379
hasIndex :: forall a . ArrayView a -> Offset -> Boolean
398
380
hasIndex 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
402
382
403
383
-- | Fetch element at index.
404
384
at :: forall a t . TypedArray a t => ArrayView a -> Offset -> Effect (Maybe t )
405
385
at a n = toMaybe <$> runEffectFn2 unsafeAtImpl a n
386
+ foreign import unsafeAtImpl :: forall a b . EffectFn2 (ArrayView a ) Offset b
406
387
407
388
infixl 3 at as !
408
389
409
-
410
- foreign import toArrayImpl :: forall a b . EffectFn1 (ArrayView a ) (Array b )
411
-
412
390
-- | Turn typed array into an array.
413
391
toArray :: forall a t . TypedArray a t => ArrayView a -> Effect (Array t )
414
392
toArray a = runEffectFn1 toArrayImpl a
393
+ foreign import toArrayImpl :: forall a b . EffectFn1 (ArrayView a ) (Array b )
0 commit comments