Skip to content

Commit bf9c682

Browse files
committed
Docs
1 parent 881787c commit bf9c682

File tree

1 file changed

+27
-24
lines changed

1 file changed

+27
-24
lines changed

src/Data/ArrayBuffer/Typed.purs

Lines changed: 27 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -118,9 +118,9 @@ foreign import indexOfImpl :: forall a b. EffectFn3 (ArrayView a) b (Nullable Of
118118
foreign 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.
122122
type Offset = Int
123-
-- | Value-oriented array length
123+
-- | Value-oriented array length.
124124
type Length = Int
125125

126126

@@ -166,19 +166,19 @@ part a x y = part' a o y
166166
part' :: forall a t. TypedArray a t => ArrayBuffer -> ByteOffset -> Length -> Effect (ArrayView a)
167167
part' 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.
170170
empty :: forall a t. TypedArray a t => Length -> Effect (ArrayView a)
171171
empty 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.
174174
fromArray :: forall a t. TypedArray a t => Array t -> Effect (ArrayView a)
175175
fromArray a = runEffectFn3 create a null null
176176

177-
-- | Fill the array with a value
177+
-- | Fill the array with a value.
178178
fill :: forall a t. TypedArray a t => t -> Offset -> Offset -> ArrayView a -> Effect Unit
179179
fill 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.
182182
set :: forall a t. TypedArray a t => ArrayView a -> Maybe Offset -> Array t -> Effect Boolean
183183
set = 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.
197197
mapWithIndex :: forall a t. TypedArray a t => (Offset -> t -> t) -> ArrayView a -> ArrayView a
198198
mapWithIndex = mapWithIndex' <<< flip
199199

200200
mapWithIndex' :: forall a t. TypedArray a t => (t -> Offset -> t) -> ArrayView a -> ArrayView a
201201
mapWithIndex' 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.
204204
traverse :: forall a t. TypedArray a t => (t -> Effect t) -> ArrayView a -> Effect (ArrayView a)
205205
traverse = traverseWithIndex' <<< ap1
206206

207-
-- | Traverses over each value, returning a new one
207+
-- | Traverses over each value, returning a new one.
208208
traverseWithIndex :: forall a t. TypedArray a t => (Offset -> t -> Effect t) -> ArrayView a -> Effect (ArrayView a)
209209
traverseWithIndex = traverseWithIndex' <<< flip
210210

211211
traverseWithIndex' :: forall a t. TypedArray a t => (t -> Offset -> Effect t) -> ArrayView a -> Effect (ArrayView a)
212212
traverseWithIndex' f a = runEffectFn2 mapImpl a (mkEffectFn2 f)
213213

214-
-- | Traverses over each value
214+
-- | Traverses over each value.
215215
traverse_ :: forall a t. TypedArray a t => (t -> Effect Unit) -> ArrayView a -> Effect Unit
216216
traverse_ = traverseWithIndex_' <<< ap1
217217

218-
-- | Traverses over each value
218+
-- | Traverses over each value.
219219
traverseWithIndex_ :: forall a t. TypedArray a t => (Offset -> t -> Effect Unit) -> ArrayView a -> Effect Unit
220220
traverseWithIndex_ = traverseWithIndex_' <<< flip
221221

222222
traverseWithIndex_' :: forall a t. TypedArray a t => (t -> Offset -> Effect Unit) -> ArrayView a -> Effect Unit
223223
traverseWithIndex_' 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.
226226
all :: forall a t. TypedArray a t => (t -> Boolean) -> ArrayView a -> Effect Boolean
227227
all = every <<< ap1
228228

229+
-- | Test a predicate (that receives also an index) to pass on all values.
229230
allWithIndex :: forall a t. TypedArray a t => (Offset -> t -> Boolean) -> ArrayView a -> Effect Boolean
230231
allWithIndex = every <<< flip
231232

232233
every :: forall a t. TypedArray a t => (t -> Offset -> Boolean) -> ArrayView a -> Effect Boolean
233234
every 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.
236237
any :: forall a t. TypedArray a t => (t -> Boolean) -> ArrayView a -> Effect Boolean
237238
any = some <<< ap1
238239

240+
-- | Test a predicate (that receives also an index) to pass on any value.
239241
anyWithIndex :: forall a t. TypedArray a t => (Offset -> t -> Boolean) -> ArrayView a -> Effect Boolean
240242
anyWithIndex = some <<< flip
241243

242244
some :: forall a t. TypedArray a t => (t -> Offset -> Boolean) -> ArrayView a -> Effect Boolean
243245
some 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.
246248
filter :: forall a t. TypedArray a t => (t -> Boolean) -> ArrayView a -> Effect (ArrayView a)
247249
filter = filterWithIndex' <<< ap1
248250

@@ -252,31 +254,31 @@ filterWithIndex = filterWithIndex' <<< flip
252254
filterWithIndex' :: forall a t. TypedArray a t => (t -> Offset -> Boolean) -> ArrayView a -> Effect (ArrayView a)
253255
filterWithIndex' 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.
256258
elem :: forall a t. TypedArray a t => t -> Maybe Offset -> ArrayView a -> Effect Boolean
257259
elem x mo a = runEffectFn3 includesImpl a x (toNullable mo)
258260

259261
-- | Fetch element at index.
260262
unsafeAt :: forall a t. TypedArray a t => Partial => ArrayView a -> Offset -> Effect t
261263
unsafeAt a o = runEffectFn2 unsafeAtImpl a o
262264

263-
-- | Folding from the left
265+
-- | Folding from the left.
264266
foldlM :: forall a t b. TypedArray a t => (b -> t -> Offset -> Effect b) -> b -> ArrayView a -> Effect b
265267
foldlM 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.
268270
foldl1M :: forall a t. TypedArray a t => (t -> t -> Offset -> Effect t) -> ArrayView a -> Effect t
269271
foldl1M f a = runEffectFn2 reduce1Impl a (mkEffectFn3 f)
270272

271-
-- | Folding from the right
273+
-- | Folding from the right.
272274
foldrM :: forall a t b. TypedArray a t => (t -> b -> Offset -> Effect b) -> b -> ArrayView a -> Effect b
273275
foldrM 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.
276278
foldr1M :: forall a t. TypedArray a t => (t -> t -> Offset -> Effect t) -> ArrayView a -> Effect t
277279
foldr1M 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.
280282
find :: forall a t. TypedArray a t => (t -> Boolean) -> ArrayView a -> Effect (Maybe t)
281283
find = findWithIndex' <<< ap1
282284

@@ -286,18 +288,19 @@ findWithIndex = findWithIndex' <<< flip
286288
findWithIndex' :: forall a t. TypedArray a t => (t -> Offset -> Boolean) -> ArrayView a -> Effect (Maybe t)
287289
findWithIndex' 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.
290292
findIndex :: forall a t. TypedArray a t => (t -> Offset -> Boolean) -> ArrayView a -> Effect (Maybe Offset)
291293
findIndex 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.
294296
indexOf :: forall a t. TypedArray a t => t -> Maybe Offset -> ArrayView a -> Effect (Maybe Offset)
295297
indexOf 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.
298300
lastIndexOf :: forall a t. TypedArray a t => t -> Maybe Offset -> ArrayView a -> Effect (Maybe Offset)
299301
lastIndexOf x mo a = toMaybe <$> runEffectFn3 lastIndexOfImpl a x (toNullable mo)
300302

303+
301304
foldl :: forall a b t. TypedArray a t => (b -> t -> b) -> b -> ArrayView a -> Effect b
302305
foldl f = foldlWithIndex' (\a x _ -> f a x)
303306

@@ -364,7 +367,7 @@ slice s e a = runEffectFn3 sliceImpl a s e
364367

365368
foreign import sortImpl :: forall a. EffectFn1 (ArrayView a) Unit
366369

367-
-- | Sorts the values in-place
370+
-- | Sorts the values in-place.
368371
sort :: forall a. ArrayView a -> Effect Unit
369372
sort a = runEffectFn1 sortImpl a
370373

0 commit comments

Comments
 (0)