@@ -326,11 +326,8 @@ findIndex fn = go 0
326
326
findLastIndex :: forall a . (a -> Boolean ) -> List a -> Maybe Int
327
327
findLastIndex fn xs = ((length xs - 1 ) - _) <$> findIndex fn (reverse xs)
328
328
329
- -- | Insert an element into a list at the specified index, returning a new
330
- -- | list or `Nothing` if the index is out-of-bounds.
331
- -- |
332
- -- | This function differs from the strict equivalent in that out-of-bounds arguments
333
- -- | result in the element being appended at the _end_ of the list.
329
+ -- | Insert an element into a list at the specified index, or append the element
330
+ -- | to the end of the list if the index is out-of-bounds, returning a new list.
334
331
-- |
335
332
-- | Running time: `O(n)`
336
333
insertAt :: forall a . Int -> a -> List a -> List a
@@ -340,11 +337,8 @@ insertAt n x xs = List (go <$> unwrap xs)
340
337
go Nil = Cons x nil
341
338
go (Cons y ys) = Cons y (insertAt (n - 1 ) x ys)
342
339
343
- -- | Delete an element from a list at the specified index, returning a new
344
- -- | list or `Nothing` if the index is out-of-bounds.
345
- -- |
346
- -- | This function differs from the strict equivalent in that out-of-bounds arguments
347
- -- | result in the original list being returned unchanged.
340
+ -- | Delete an element from a list at the specified index, returning a new list,
341
+ -- | or return the original list unchanged if the index is out-of-bounds.
348
342
-- |
349
343
-- | Running time: `O(n)`
350
344
deleteAt :: forall a . Int -> List a -> List a
@@ -354,11 +348,8 @@ deleteAt n xs = List (go n <$> unwrap xs)
354
348
go 0 (Cons y ys) = step ys
355
349
go n' (Cons y ys) = Cons y (deleteAt (n' - 1 ) ys)
356
350
357
- -- | Update the element at the specified index, returning a new
358
- -- | list or `Nothing` if the index is out-of-bounds.
359
- -- |
360
- -- | This function differs from the strict equivalent in that out-of-bounds arguments
361
- -- | result in the original list being returned unchanged.
351
+ -- | Update the element at the specified index, returning a new list,
352
+ -- | or return the original list unchanged if the index is out-of-bounds.
362
353
-- |
363
354
-- | Running time: `O(n)`
364
355
updateAt :: forall a . Int -> a -> List a -> List a
@@ -369,22 +360,16 @@ updateAt n x xs = List (go n <$> unwrap xs)
369
360
go n' (Cons y ys) = Cons y (updateAt (n' - 1 ) x ys)
370
361
371
362
-- | Update the element at the specified index by applying a function to
372
- -- | the current value, returning a new list or `Nothing` if the index is
373
- -- | out-of-bounds.
374
- -- |
375
- -- | This function differs from the strict equivalent in that out-of-bounds arguments
376
- -- | result in the original list being returned unchanged.
363
+ -- | the current value, returning a new list, or return the original list unchanged
364
+ -- | if the index is out-of-bounds.
377
365
-- |
378
366
-- | Running time: `O(n)`
379
367
modifyAt :: forall a . Int -> (a -> a ) -> List a -> List a
380
368
modifyAt n f = alterAt n (Just <<< f)
381
369
382
370
-- | Update or delete the element at the specified index by applying a
383
- -- | function to the current value, returning a new list or `Nothing` if the
384
- -- | index is out-of-bounds.
385
- -- |
386
- -- | This function differs from the strict equivalent in that out-of-bounds arguments
387
- -- | result in the original list being returned unchanged.
371
+ -- | function to the current value, returning a new list, or return the
372
+ -- | original list unchanged if the index is out-of-bounds.
388
373
-- |
389
374
-- | Running time: `O(n)`
390
375
alterAt :: forall a . Int -> (a -> Maybe a ) -> List a -> List a
0 commit comments