From 0df0fe02f8db103f04260ca47bc89d4712ed106f Mon Sep 17 00:00:00 2001 From: milesfrain Date: Thu, 23 Apr 2020 16:38:21 -0600 Subject: [PATCH 1/2] Fix lazy list docs where original is returned instead of nothing --- src/Data/List/Lazy.purs | 35 ++++++++++------------------------- 1 file changed, 10 insertions(+), 25 deletions(-) diff --git a/src/Data/List/Lazy.purs b/src/Data/List/Lazy.purs index b9b7ca4..c691c19 100644 --- a/src/Data/List/Lazy.purs +++ b/src/Data/List/Lazy.purs @@ -326,11 +326,8 @@ findIndex fn = go 0 findLastIndex :: forall a. (a -> Boolean) -> List a -> Maybe Int findLastIndex fn xs = ((length xs - 1) - _) <$> findIndex fn (reverse xs) --- | Insert an element into a list at the specified index, returning a new --- | list or `Nothing` if the index is out-of-bounds. --- | --- | This function differs from the strict equivalent in that out-of-bounds arguments --- | result in the element being appended at the _end_ of the list. +-- | Insert an element into a list at the specified index, or append the element +-- | to the _end_ of the list if the index is out-of-bounds, returning a new list. -- | -- | Running time: `O(n)` insertAt :: forall a. Int -> a -> List a -> List a @@ -340,11 +337,8 @@ insertAt n x xs = List (go <$> unwrap xs) go Nil = Cons x nil go (Cons y ys) = Cons y (insertAt (n - 1) x ys) --- | Delete an element from a list at the specified index, returning a new --- | list or `Nothing` if the index is out-of-bounds. --- | --- | This function differs from the strict equivalent in that out-of-bounds arguments --- | result in the original list being returned unchanged. +-- | Delete an element from a list at the specified index, returning a new list, +-- | or return the original list unchanged if the index is out-of-bounds. -- | -- | Running time: `O(n)` deleteAt :: forall a. Int -> List a -> List a @@ -354,11 +348,8 @@ deleteAt n xs = List (go n <$> unwrap xs) go 0 (Cons y ys) = step ys go n' (Cons y ys) = Cons y (deleteAt (n' - 1) ys) --- | Update the element at the specified index, returning a new --- | list or `Nothing` if the index is out-of-bounds. --- | --- | This function differs from the strict equivalent in that out-of-bounds arguments --- | result in the original list being returned unchanged. +-- | Update the element at the specified index, returning a new list, +-- | or return the original list unchanged if the index is out-of-bounds. -- | -- | Running time: `O(n)` updateAt :: forall a. Int -> a -> List a -> List a @@ -369,22 +360,16 @@ updateAt n x xs = List (go n <$> unwrap xs) go n' (Cons y ys) = Cons y (updateAt (n' - 1) x ys) -- | Update the element at the specified index by applying a function to --- | the current value, returning a new list or `Nothing` if the index is --- | out-of-bounds. --- | --- | This function differs from the strict equivalent in that out-of-bounds arguments --- | result in the original list being returned unchanged. +-- | the current value, returning a new list, or return the original list unchanged +-- | if the index is out-of-bounds. -- | -- | Running time: `O(n)` modifyAt :: forall a. Int -> (a -> a) -> List a -> List a modifyAt n f = alterAt n (Just <<< f) -- | Update or delete the element at the specified index by applying a --- | function to the current value, returning a new list or `Nothing` if the --- | index is out-of-bounds. --- | --- | This function differs from the strict equivalent in that out-of-bounds arguments --- | result in the original list being returned unchanged. +-- | function to the current value, returning a new list, or return the +-- | original list unchanged if the index is out-of-bounds. -- | -- | Running time: `O(n)` alterAt :: forall a. Int -> (a -> Maybe a) -> List a -> List a From 6747c9014fb1211743e08e8d5701ab1c3ff8d54e Mon Sep 17 00:00:00 2001 From: milesfrain Date: Thu, 23 Apr 2020 16:47:15 -0600 Subject: [PATCH 2/2] review feedback --- src/Data/List/Lazy.purs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Data/List/Lazy.purs b/src/Data/List/Lazy.purs index c691c19..7a9ddfe 100644 --- a/src/Data/List/Lazy.purs +++ b/src/Data/List/Lazy.purs @@ -327,7 +327,7 @@ findLastIndex :: forall a. (a -> Boolean) -> List a -> Maybe Int findLastIndex fn xs = ((length xs - 1) - _) <$> findIndex fn (reverse xs) -- | Insert an element into a list at the specified index, or append the element --- | to the _end_ of the list if the index is out-of-bounds, returning a new list. +-- | to the end of the list if the index is out-of-bounds, returning a new list. -- | -- | Running time: `O(n)` insertAt :: forall a. Int -> a -> List a -> List a