@@ -118,9 +118,9 @@ foreign import indexOfImpl :: forall a b. EffectFn3 (ArrayView a) b (Nullable Of
118118foreign import lastIndexOfImpl :: forall a b . EffectFn3 (ArrayView a ) b (Nullable Offset ) (Nullable Offset )
119119
120120
121- -- | Value-oriented array offset
121+ -- | Value-oriented array offset.
122122type Offset = Int
123- -- | Value-oriented array length
123+ -- | Value-oriented array length.
124124type Length = Int
125125
126126
@@ -166,19 +166,19 @@ part a x y = part' a o y
166166part' :: forall a t . TypedArray a t => ArrayBuffer -> ByteOffset -> Length -> Effect (ArrayView a )
167167part' a x y = runEffectFn3 create a (notNull x) (notNull y)
168168
169- -- | Creates an empty typed array, where each value is assigned 0
169+ -- | Creates an empty typed array, where each value is assigned 0.
170170empty :: forall a t . TypedArray a t => Length -> Effect (ArrayView a )
171171empty n = runEffectFn3 create n null null
172172
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.
174174fromArray :: forall a t . TypedArray a t => Array t -> Effect (ArrayView a )
175175fromArray a = runEffectFn3 create a null null
176176
177- -- | Fill the array with a value
177+ -- | Fill the array with a value.
178178fill :: forall a t . TypedArray a t => t -> Offset -> Offset -> ArrayView a -> Effect Unit
179179fill x s e a = runEffectFn4 fillImpl x s e a
180180
181- -- | Stores multiple values into the typed array
181+ -- | Stores multiple values into the typed array.
182182set :: forall a t . TypedArray a t => ArrayView a -> Maybe Offset -> Array t -> Effect Boolean
183183set = setInternal A .length
184184
@@ -193,56 +193,58 @@ map = mapWithIndex' <<< ap1
193193
194194-- | Apply a function to each element in an array, supplying a
195195-- | 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.
197197mapWithIndex :: forall a t . TypedArray a t => (Offset -> t -> t ) -> ArrayView a -> ArrayView a
198198mapWithIndex = mapWithIndex' <<< flip
199199
200200mapWithIndex' :: forall a t . TypedArray a t => (t -> Offset -> t ) -> ArrayView a -> ArrayView a
201201mapWithIndex' f a = unsafePerformEffect (runEffectFn2 mapImpl a (mkEffectFn2 (\x o -> pure (f x o))))
202202
203- -- | Traverses over each value, returning a new one
203+ -- | Traverses over each value, returning a new one.
204204traverse :: forall a t . TypedArray a t => (t -> Effect t ) -> ArrayView a -> Effect (ArrayView a )
205205traverse = traverseWithIndex' <<< ap1
206206
207- -- | Traverses over each value, returning a new one
207+ -- | Traverses over each value, returning a new one.
208208traverseWithIndex :: forall a t . TypedArray a t => (Offset -> t -> Effect t ) -> ArrayView a -> Effect (ArrayView a )
209209traverseWithIndex = traverseWithIndex' <<< flip
210210
211211traverseWithIndex' :: forall a t . TypedArray a t => (t -> Offset -> Effect t ) -> ArrayView a -> Effect (ArrayView a )
212212traverseWithIndex' f a = runEffectFn2 mapImpl a (mkEffectFn2 f)
213213
214- -- | Traverses over each value
214+ -- | Traverses over each value.
215215traverse_ :: forall a t . TypedArray a t => (t -> Effect Unit ) -> ArrayView a -> Effect Unit
216216traverse_ = traverseWithIndex_' <<< ap1
217217
218- -- | Traverses over each value
218+ -- | Traverses over each value.
219219traverseWithIndex_ :: forall a t . TypedArray a t => (Offset -> t -> Effect Unit ) -> ArrayView a -> Effect Unit
220220traverseWithIndex_ = traverseWithIndex_' <<< flip
221221
222222traverseWithIndex_' :: forall a t . TypedArray a t => (t -> Offset -> Effect Unit ) -> ArrayView a -> Effect Unit
223223traverseWithIndex_' f a = runEffectFn2 forEachImpl a (mkEffectFn2 f)
224224
225- -- | Test a predicate to pass on all values
225+ -- | Test a predicate to pass on all values.
226226all :: forall a t . TypedArray a t => (t -> Boolean ) -> ArrayView a -> Effect Boolean
227227all = every <<< ap1
228228
229+ -- | Test a predicate (that receives also an index) to pass on all values.
229230allWithIndex :: forall a t . TypedArray a t => (Offset -> t -> Boolean ) -> ArrayView a -> Effect Boolean
230231allWithIndex = every <<< flip
231232
232233every :: forall a t . TypedArray a t => (t -> Offset -> Boolean ) -> ArrayView a -> Effect Boolean
233234every p a = runEffectFn2 everyImpl a (mkFn2 p)
234235
235- -- | Test a predicate to pass on any value
236+ -- | Test a predicate to pass on any value.
236237any :: forall a t . TypedArray a t => (t -> Boolean ) -> ArrayView a -> Effect Boolean
237238any = some <<< ap1
238239
240+ -- | Test a predicate (that receives also an index) to pass on any value.
239241anyWithIndex :: forall a t . TypedArray a t => (Offset -> t -> Boolean ) -> ArrayView a -> Effect Boolean
240242anyWithIndex = some <<< flip
241243
242244some :: forall a t . TypedArray a t => (t -> Offset -> Boolean ) -> ArrayView a -> Effect Boolean
243245some p a = runEffectFn2 someImpl a (mkFn2 p)
244246
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.
246248filter :: forall a t . TypedArray a t => (t -> Boolean ) -> ArrayView a -> Effect (ArrayView a )
247249filter = filterWithIndex' <<< ap1
248250
@@ -252,31 +254,31 @@ filterWithIndex = filterWithIndex' <<< flip
252254filterWithIndex' :: forall a t . TypedArray a t => (t -> Offset -> Boolean ) -> ArrayView a -> Effect (ArrayView a )
253255filterWithIndex' p a = runEffectFn2 filterImpl a (mkFn2 p)
254256
255- -- | Tests if a value is an element of the typed array
257+ -- | Tests if a value is an element of the typed array.
256258elem :: forall a t . TypedArray a t => t -> Maybe Offset -> ArrayView a -> Effect Boolean
257259elem x mo a = runEffectFn3 includesImpl a x (toNullable mo)
258260
259261-- | Fetch element at index.
260262unsafeAt :: forall a t . TypedArray a t => Partial => ArrayView a -> Offset -> Effect t
261263unsafeAt a o = runEffectFn2 unsafeAtImpl a o
262264
263- -- | Folding from the left
265+ -- | Folding from the left.
264266foldlM :: forall a t b . TypedArray a t => (b -> t -> Offset -> Effect b ) -> b -> ArrayView a -> Effect b
265267foldlM f i a = runEffectFn3 reduceImpl a (mkEffectFn3 f) i
266268
267- -- | Assumes the typed array is non-empty
269+ -- | Folding from the left. Assumes the typed array is non-empty.
268270foldl1M :: forall a t . TypedArray a t => (t -> t -> Offset -> Effect t ) -> ArrayView a -> Effect t
269271foldl1M f a = runEffectFn2 reduce1Impl a (mkEffectFn3 f)
270272
271- -- | Folding from the right
273+ -- | Folding from the right.
272274foldrM :: forall a t b . TypedArray a t => (t -> b -> Offset -> Effect b ) -> b -> ArrayView a -> Effect b
273275foldrM f i a = runEffectFn3 reduceRightImpl a (mkEffectFn3 (\acc x o -> f x acc o)) i
274276
275- -- | Assumes the typed array is non-empty
277+ -- | Folding from the right. Assumes the typed array is non-empty.
276278foldr1M :: forall a t . TypedArray a t => (t -> t -> Offset -> Effect t ) -> ArrayView a -> Effect t
277279foldr1M f a = runEffectFn2 reduceRight1Impl a (mkEffectFn3 (\acc x o -> f x acc o))
278280
279- -- | Returns the first value satisfying the predicate
281+ -- | Returns the first value satisfying the predicate.
280282find :: forall a t . TypedArray a t => (t -> Boolean ) -> ArrayView a -> Effect (Maybe t )
281283find = findWithIndex' <<< ap1
282284
@@ -286,18 +288,19 @@ findWithIndex = findWithIndex' <<< flip
286288findWithIndex' :: forall a t . TypedArray a t => (t -> Offset -> Boolean ) -> ArrayView a -> Effect (Maybe t )
287289findWithIndex' f a = toMaybe <$> runEffectFn2 findImpl a (mkFn2 f)
288290
289- -- | Returns the first index of the value satisfying the predicate
291+ -- | Returns the first index of the value satisfying the predicate.
290292findIndex :: forall a t . TypedArray a t => (t -> Offset -> Boolean ) -> ArrayView a -> Effect (Maybe Offset )
291293findIndex f a = toMaybe <$> runEffectFn2 findIndexImpl a (mkFn2 f)
292294
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.
294296indexOf :: forall a t . TypedArray a t => t -> Maybe Offset -> ArrayView a -> Effect (Maybe Offset )
295297indexOf x mo a = toMaybe <$> runEffectFn3 indexOfImpl a x (toNullable mo)
296298
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.
298300lastIndexOf :: forall a t . TypedArray a t => t -> Maybe Offset -> ArrayView a -> Effect (Maybe Offset )
299301lastIndexOf x mo a = toMaybe <$> runEffectFn3 lastIndexOfImpl a x (toNullable mo)
300302
303+
301304foldl :: forall a b t . TypedArray a t => (b -> t -> b ) -> b -> ArrayView a -> Effect b
302305foldl f = foldlWithIndex' (\a x _ -> f a x)
303306
@@ -364,7 +367,7 @@ slice s e a = runEffectFn3 sliceImpl a s e
364367
365368foreign import sortImpl :: forall a . EffectFn1 (ArrayView a ) Unit
366369
367- -- | Sorts the values in-place
370+ -- | Sorts the values in-place.
368371sort :: forall a . ArrayView a -> Effect Unit
369372sort a = runEffectFn1 sortImpl a
370373
0 commit comments