@@ -118,9 +118,9 @@ foreign import indexOfImpl :: forall a b. EffectFn3 (ArrayView a) b (Nullable Of
118
118
foreign import lastIndexOfImpl :: forall a b . EffectFn3 (ArrayView a ) b (Nullable Offset ) (Nullable Offset )
119
119
120
120
121
- -- | Value-oriented array offset
121
+ -- | Value-oriented array offset.
122
122
type Offset = Int
123
- -- | Value-oriented array length
123
+ -- | Value-oriented array length.
124
124
type Length = Int
125
125
126
126
@@ -166,19 +166,19 @@ part a x y = part' a o y
166
166
part' :: forall a t . TypedArray a t => ArrayBuffer -> ByteOffset -> Length -> Effect (ArrayView a )
167
167
part' a x y = runEffectFn3 create a (notNull x) (notNull y)
168
168
169
- -- | Creates an empty typed array, where each value is assigned 0
169
+ -- | Creates an empty typed array, where each value is assigned 0.
170
170
empty :: forall a t . TypedArray a t => Length -> Effect (ArrayView a )
171
171
empty n = runEffectFn3 create n null null
172
172
173
- -- | Creates a typed array from an input array of values, to be binary serialized
173
+ -- | Creates a typed array from an input array of values, to be binary serialized.
174
174
fromArray :: forall a t . TypedArray a t => Array t -> Effect (ArrayView a )
175
175
fromArray a = runEffectFn3 create a null null
176
176
177
- -- | Fill the array with a value
177
+ -- | Fill the array with a value.
178
178
fill :: forall a t . TypedArray a t => t -> Offset -> Offset -> ArrayView a -> Effect Unit
179
179
fill x s e a = runEffectFn4 fillImpl x s e a
180
180
181
- -- | Stores multiple values into the typed array
181
+ -- | Stores multiple values into the typed array.
182
182
set :: forall a t . TypedArray a t => ArrayView a -> Maybe Offset -> Array t -> Effect Boolean
183
183
set = setInternal A .length
184
184
@@ -193,56 +193,58 @@ map = mapWithIndex' <<< ap1
193
193
194
194
-- | Apply a function to each element in an array, supplying a
195
195
-- | generated zero-based index integer along with the element,
196
- -- | creating a typed array with the new elements
196
+ -- | creating a typed array with the new elements.
197
197
mapWithIndex :: forall a t . TypedArray a t => (Offset -> t -> t ) -> ArrayView a -> ArrayView a
198
198
mapWithIndex = mapWithIndex' <<< flip
199
199
200
200
mapWithIndex' :: forall a t . TypedArray a t => (t -> Offset -> t ) -> ArrayView a -> ArrayView a
201
201
mapWithIndex' f a = unsafePerformEffect (runEffectFn2 mapImpl a (mkEffectFn2 (\x o -> pure (f x o))))
202
202
203
- -- | Traverses over each value, returning a new one
203
+ -- | Traverses over each value, returning a new one.
204
204
traverse :: forall a t . TypedArray a t => (t -> Effect t ) -> ArrayView a -> Effect (ArrayView a )
205
205
traverse = traverseWithIndex' <<< ap1
206
206
207
- -- | Traverses over each value, returning a new one
207
+ -- | Traverses over each value, returning a new one.
208
208
traverseWithIndex :: forall a t . TypedArray a t => (Offset -> t -> Effect t ) -> ArrayView a -> Effect (ArrayView a )
209
209
traverseWithIndex = traverseWithIndex' <<< flip
210
210
211
211
traverseWithIndex' :: forall a t . TypedArray a t => (t -> Offset -> Effect t ) -> ArrayView a -> Effect (ArrayView a )
212
212
traverseWithIndex' f a = runEffectFn2 mapImpl a (mkEffectFn2 f)
213
213
214
- -- | Traverses over each value
214
+ -- | Traverses over each value.
215
215
traverse_ :: forall a t . TypedArray a t => (t -> Effect Unit ) -> ArrayView a -> Effect Unit
216
216
traverse_ = traverseWithIndex_' <<< ap1
217
217
218
- -- | Traverses over each value
218
+ -- | Traverses over each value.
219
219
traverseWithIndex_ :: forall a t . TypedArray a t => (Offset -> t -> Effect Unit ) -> ArrayView a -> Effect Unit
220
220
traverseWithIndex_ = traverseWithIndex_' <<< flip
221
221
222
222
traverseWithIndex_' :: forall a t . TypedArray a t => (t -> Offset -> Effect Unit ) -> ArrayView a -> Effect Unit
223
223
traverseWithIndex_' f a = runEffectFn2 forEachImpl a (mkEffectFn2 f)
224
224
225
- -- | Test a predicate to pass on all values
225
+ -- | Test a predicate to pass on all values.
226
226
all :: forall a t . TypedArray a t => (t -> Boolean ) -> ArrayView a -> Effect Boolean
227
227
all = every <<< ap1
228
228
229
+ -- | Test a predicate (that receives also an index) to pass on all values.
229
230
allWithIndex :: forall a t . TypedArray a t => (Offset -> t -> Boolean ) -> ArrayView a -> Effect Boolean
230
231
allWithIndex = every <<< flip
231
232
232
233
every :: forall a t . TypedArray a t => (t -> Offset -> Boolean ) -> ArrayView a -> Effect Boolean
233
234
every p a = runEffectFn2 everyImpl a (mkFn2 p)
234
235
235
- -- | Test a predicate to pass on any value
236
+ -- | Test a predicate to pass on any value.
236
237
any :: forall a t . TypedArray a t => (t -> Boolean ) -> ArrayView a -> Effect Boolean
237
238
any = some <<< ap1
238
239
240
+ -- | Test a predicate (that receives also an index) to pass on any value.
239
241
anyWithIndex :: forall a t . TypedArray a t => (Offset -> t -> Boolean ) -> ArrayView a -> Effect Boolean
240
242
anyWithIndex = some <<< flip
241
243
242
244
some :: forall a t . TypedArray a t => (t -> Offset -> Boolean ) -> ArrayView a -> Effect Boolean
243
245
some p a = runEffectFn2 someImpl a (mkFn2 p)
244
246
245
- -- | Returns a new typed array with all values that pass the predicate
247
+ -- | Returns a new typed array with all values that pass the predicate.
246
248
filter :: forall a t . TypedArray a t => (t -> Boolean ) -> ArrayView a -> Effect (ArrayView a )
247
249
filter = filterWithIndex' <<< ap1
248
250
@@ -252,31 +254,31 @@ filterWithIndex = filterWithIndex' <<< flip
252
254
filterWithIndex' :: forall a t . TypedArray a t => (t -> Offset -> Boolean ) -> ArrayView a -> Effect (ArrayView a )
253
255
filterWithIndex' p a = runEffectFn2 filterImpl a (mkFn2 p)
254
256
255
- -- | Tests if a value is an element of the typed array
257
+ -- | Tests if a value is an element of the typed array.
256
258
elem :: forall a t . TypedArray a t => t -> Maybe Offset -> ArrayView a -> Effect Boolean
257
259
elem x mo a = runEffectFn3 includesImpl a x (toNullable mo)
258
260
259
261
-- | Fetch element at index.
260
262
unsafeAt :: forall a t . TypedArray a t => Partial => ArrayView a -> Offset -> Effect t
261
263
unsafeAt a o = runEffectFn2 unsafeAtImpl a o
262
264
263
- -- | Folding from the left
265
+ -- | Folding from the left.
264
266
foldlM :: forall a t b . TypedArray a t => (b -> t -> Offset -> Effect b ) -> b -> ArrayView a -> Effect b
265
267
foldlM f i a = runEffectFn3 reduceImpl a (mkEffectFn3 f) i
266
268
267
- -- | Assumes the typed array is non-empty
269
+ -- | Folding from the left. Assumes the typed array is non-empty.
268
270
foldl1M :: forall a t . TypedArray a t => (t -> t -> Offset -> Effect t ) -> ArrayView a -> Effect t
269
271
foldl1M f a = runEffectFn2 reduce1Impl a (mkEffectFn3 f)
270
272
271
- -- | Folding from the right
273
+ -- | Folding from the right.
272
274
foldrM :: forall a t b . TypedArray a t => (t -> b -> Offset -> Effect b ) -> b -> ArrayView a -> Effect b
273
275
foldrM f i a = runEffectFn3 reduceRightImpl a (mkEffectFn3 (\acc x o -> f x acc o)) i
274
276
275
- -- | Assumes the typed array is non-empty
277
+ -- | Folding from the right. Assumes the typed array is non-empty.
276
278
foldr1M :: forall a t . TypedArray a t => (t -> t -> Offset -> Effect t ) -> ArrayView a -> Effect t
277
279
foldr1M f a = runEffectFn2 reduceRight1Impl a (mkEffectFn3 (\acc x o -> f x acc o))
278
280
279
- -- | Returns the first value satisfying the predicate
281
+ -- | Returns the first value satisfying the predicate.
280
282
find :: forall a t . TypedArray a t => (t -> Boolean ) -> ArrayView a -> Effect (Maybe t )
281
283
find = findWithIndex' <<< ap1
282
284
@@ -286,18 +288,19 @@ findWithIndex = findWithIndex' <<< flip
286
288
findWithIndex' :: forall a t . TypedArray a t => (t -> Offset -> Boolean ) -> ArrayView a -> Effect (Maybe t )
287
289
findWithIndex' f a = toMaybe <$> runEffectFn2 findImpl a (mkFn2 f)
288
290
289
- -- | Returns the first index of the value satisfying the predicate
291
+ -- | Returns the first index of the value satisfying the predicate.
290
292
findIndex :: forall a t . TypedArray a t => (t -> Offset -> Boolean ) -> ArrayView a -> Effect (Maybe Offset )
291
293
findIndex f a = toMaybe <$> runEffectFn2 findIndexImpl a (mkFn2 f)
292
294
293
- -- | Returns the first index of the element, if it exists, from the left
295
+ -- | Returns the first index of the element, if it exists, from the left.
294
296
indexOf :: forall a t . TypedArray a t => t -> Maybe Offset -> ArrayView a -> Effect (Maybe Offset )
295
297
indexOf x mo a = toMaybe <$> runEffectFn3 indexOfImpl a x (toNullable mo)
296
298
297
- -- | Returns the first index of the element, if it exists, from the right
299
+ -- | Returns the first index of the element, if it exists, from the right.
298
300
lastIndexOf :: forall a t . TypedArray a t => t -> Maybe Offset -> ArrayView a -> Effect (Maybe Offset )
299
301
lastIndexOf x mo a = toMaybe <$> runEffectFn3 lastIndexOfImpl a x (toNullable mo)
300
302
303
+
301
304
foldl :: forall a b t . TypedArray a t => (b -> t -> b ) -> b -> ArrayView a -> Effect b
302
305
foldl f = foldlWithIndex' (\a x _ -> f a x)
303
306
@@ -364,7 +367,7 @@ slice s e a = runEffectFn3 sliceImpl a s e
364
367
365
368
foreign import sortImpl :: forall a . EffectFn1 (ArrayView a ) Unit
366
369
367
- -- | Sorts the values in-place
370
+ -- | Sorts the values in-place.
368
371
sort :: forall a . ArrayView a -> Effect Unit
369
372
sort a = runEffectFn1 sortImpl a
370
373
0 commit comments