From a6067649c1dece59aba2fa200aadedebdac0aea0 Mon Sep 17 00:00:00 2001 From: Gary Burgess Date: Sun, 13 Nov 2016 23:35:56 +0000 Subject: [PATCH 1/2] Update badges Remove broken dependency status badge & switch version from bower specific --- README.md | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 5165890..86d3952 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,7 @@ # purescript-lists -[![Latest release](http://img.shields.io/bower/v/purescript-lists.svg)](https://github.com/purescript/purescript-lists/releases) -[![Build Status](https://travis-ci.org/purescript/purescript-lists.svg?branch=master)](https://travis-ci.org/purescript/purescript-lists) -[![Dependency Status](https://www.versioneye.com/user/projects/55848c8a363861001d00033b/badge.svg?style=flat)](https://www.versioneye.com/user/projects/55848c8a363861001d00033b) +[![Latest release](http://img.shields.io/github/release/purescript/purescript-lists.svg)](https://github.com/purescript/purescript-lists/releases) +[![Build status](https://travis-ci.org/purescript/purescript-lists.svg?branch=master)](https://travis-ci.org/purescript/purescript-lists) This library defines strict and lazy linked lists, and associated helper functions and type class instances. From 8b350bf444957ccbd978d29cbd3d0e2c9f0aa3cf Mon Sep 17 00:00:00 2001 From: Gary Burgess Date: Sun, 13 Nov 2016 23:36:01 +0000 Subject: [PATCH 2/2] Fix shadowed name warnings --- src/Data/List/Lazy.purs | 56 ++++++++++++++++++----------------- src/Data/List/Lazy/Types.purs | 24 +++++++-------- src/Data/List/Types.purs | 10 +++---- 3 files changed, 46 insertions(+), 44 deletions(-) diff --git a/src/Data/List/Lazy.purs b/src/Data/List/Lazy.purs index 1975595..705ed4c 100644 --- a/src/Data/List/Lazy.purs +++ b/src/Data/List/Lazy.purs @@ -189,7 +189,7 @@ length :: forall a. List a -> Int length xs = go (step xs) where go Nil = 0 - go (Cons _ xs) = 1 + go (step xs) + go (Cons _ xs') = 1 + go (step xs') -------------------------------------------------------------------------------- -- Extending arrays ------------------------------------------------------------ @@ -234,11 +234,12 @@ head xs = _.head <$> uncons xs -- | -- | Running time: `O(n)`. last :: forall a. List a -> Maybe a -last xs = go (step xs) +last = go <<< step where - go (Cons x xs) | null xs = Just x - | otherwise = go (step xs) - go _ = Nothing + go (Cons x xs) + | null xs = Just x + | otherwise = go (step xs) + go _ = Nothing -- | Get all but the first element of a list, or `Nothing` if the list is empty. -- | @@ -250,12 +251,13 @@ tail xs = _.tail <$> uncons xs -- | -- | Running time: `O(n)` init :: forall a. List a -> Maybe (List a) -init xs = go (step xs) +init = go <<< step where go :: Step a -> Maybe (List a) - go (Cons x xs) | null xs = Just nil - | otherwise = cons x <$> go (step xs) - go _ = Nothing + go (Cons x xs) + | null xs = Just nil + | otherwise = cons x <$> go (step xs) + go _ = Nothing -- | Break a list into its first element, and the remaining elements, -- | or `Nothing` if the list is empty. @@ -263,8 +265,8 @@ init xs = go (step xs) -- | Running time: `O(1)` uncons :: forall a. List a -> Maybe { head :: a, tail :: List a } uncons xs = case step xs of - Nil -> Nothing - Cons x xs -> Just { head: x, tail: xs } + Nil -> Nothing + Cons x xs' -> Just { head: x, tail: xs' } -------------------------------------------------------------------------------- -- Indexed operations ---------------------------------------------------------- @@ -332,7 +334,7 @@ deleteAt n xs = List (go n <$> unwrap xs) where go _ Nil = Nil go 0 (Cons y ys) = step ys - go n (Cons y ys) = Cons y (deleteAt (n - 1) 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. @@ -346,7 +348,7 @@ updateAt n x xs = List (go n <$> unwrap xs) where go _ Nil = Nil go 0 (Cons _ ys) = Cons x ys - go n (Cons y ys) = Cons y (updateAt (n - 1) x ys) + 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 @@ -374,7 +376,7 @@ alterAt n f xs = List (go n <$> unwrap xs) go 0 (Cons y ys) = case f y of Nothing -> step ys Just y' -> Cons y' ys - go n (Cons y ys) = Cons y (alterAt (n - 1) f ys) + go n' (Cons y ys) = Cons y (alterAt (n' - 1) f ys) -------------------------------------------------------------------------------- -- Transformations ------------------------------------------------------------- @@ -384,7 +386,7 @@ alterAt n f xs = List (go n <$> unwrap xs) -- | -- | Running time: `O(n)` reverse :: forall a. List a -> List a -reverse xs = go nil (step xs) +reverse = go nil <<< step where go acc Nil = acc go acc (Cons x xs) = go (cons x acc) (step xs) @@ -406,7 +408,7 @@ concatMap = flip bind -- | -- | Running time: `O(n)` filter :: forall a. (a -> Boolean) -> List a -> List a -filter p xs = List (go <$> unwrap xs) +filter p = List <<< map go <<< unwrap where go Nil = Nil go (Cons x xs) @@ -436,7 +438,7 @@ filterM p list = -- | -- | Running time: `O(n)` mapMaybe :: forall a b. (a -> Maybe b) -> List a -> List b -mapMaybe f xs = List (go <$> unwrap xs) +mapMaybe f = List <<< map go <<< unwrap where go Nil = Nil go (Cons x xs) = @@ -465,18 +467,18 @@ slice start end xs = take (end - start) (drop start xs) -- | -- | Running time: `O(n)` where `n` is the number of elements to take. take :: forall a. Int -> List a -> List a -take n xs = List (go n <$> unwrap xs) +take n = List <<< map (go n) <<< unwrap where go :: Int -> Step a -> Step a go i _ | i <= 0 = Nil go _ Nil = Nil - go n (Cons x xs) = Cons x (take (n - 1) xs) + go n' (Cons x xs) = Cons x (take (n' - 1) xs) -- | Take those elements from the front of a list which match a predicate. -- | -- | Running time (worst case): `O(n)` takeWhile :: forall a. (a -> Boolean) -> List a -> List a -takeWhile p xs = List (go <$> unwrap xs) +takeWhile p = List <<< map go <<< unwrap where go (Cons x xs) | p x = Cons x (takeWhile p xs) go _ = Nil @@ -485,17 +487,17 @@ takeWhile p xs = List (go <$> unwrap xs) -- | -- | Running time: `O(n)` where `n` is the number of elements to drop. drop :: forall a. Int -> List a -> List a -drop n xs = List (go n <$> unwrap xs) +drop n = List <<< map (go n) <<< unwrap where go 0 xs = xs go _ Nil = Nil - go n (Cons x xs) = go (n - 1) (step xs) + go n' (Cons x xs) = go (n' - 1) (step xs) -- | Drop those elements from the front of a list which match a predicate. -- | -- | Running time (worst case): `O(n)` dropWhile :: forall a. (a -> Boolean) -> List a -> List a -dropWhile p xs = go (step xs) +dropWhile p = go <<< step where go (Cons x xs) | p x = go (step xs) go xs = fromStep xs @@ -537,7 +539,7 @@ group = groupBy (==) -- | -- | Running time: `O(n)` groupBy :: forall a. (a -> a -> Boolean) -> List a -> List (NEL.NonEmptyList a) -groupBy eq xs = List (go <$> unwrap xs) +groupBy eq = List <<< map go <<< unwrap where go Nil = Nil go (Cons x xs) = @@ -560,7 +562,7 @@ nub = nubBy eq -- | -- | Running time: `O(n^2)` nubBy :: forall a. (a -> a -> Boolean) -> List a -> List a -nubBy eq xs = List (go <$> unwrap xs) +nubBy eq = List <<< map go <<< unwrap where go Nil = Nil go (Cons x xs) = Cons x (nubBy eq (filter (\y -> not (eq x y)) xs)) @@ -678,8 +680,8 @@ transpose xs = case uncons h of Nothing -> transpose xss - Just { head: x, tail: xs } -> - (x : mapMaybe head xss) : transpose (xs : mapMaybe tail xss) + Just { head: x, tail: xs' } -> + (x : mapMaybe head xss) : transpose (xs' : mapMaybe tail xss) -------------------------------------------------------------------------------- -- Folding --------------------------------------------------------------------- diff --git a/src/Data/List/Lazy/Types.purs b/src/Data/List/Lazy/Types.purs index dc9852e..6edc77a 100644 --- a/src/Data/List/Lazy/Types.purs +++ b/src/Data/List/Lazy/Types.purs @@ -58,14 +58,14 @@ instance showList :: Show a => Show (List a) where show xs = "fromStrict (" <> go (step xs) <> ")" where go Nil = "Nil" - go (Cons x xs) = "(Cons " <> show x <> " " <> go (step xs) <> ")" + go (Cons x xs') = "(Cons " <> show x <> " " <> go (step xs') <> ")" instance eqList :: Eq a => Eq (List a) where eq xs ys = go (step xs) (step ys) where go Nil Nil = true - go (Cons x xs) (Cons y ys) - | x == y = go (step xs) (step ys) + go (Cons x xs') (Cons y ys') + | x == y = go (step xs') (step ys') go _ _ = false instance ordList :: Ord a => Ord (List a) where @@ -74,9 +74,9 @@ instance ordList :: Ord a => Ord (List a) where go Nil Nil = EQ go Nil _ = LT go _ Nil = GT - go (Cons x xs) (Cons y ys) = + go (Cons x xs') (Cons y ys') = case compare x y of - EQ -> go (step xs) (step ys) + EQ -> go (step xs') (step ys') other -> other instance lazyList :: Z.Lazy (List a) where @@ -86,7 +86,7 @@ instance semigroupList :: Semigroup (List a) where append xs ys = List (go <$> unwrap xs) where go Nil = step ys - go (Cons x xs) = Cons x (xs <> ys) + go (Cons x xs') = Cons x (xs' <> ys) instance monoidList :: Monoid (List a) where mempty = nil @@ -95,7 +95,7 @@ instance functorList :: Functor List where map f xs = List (go <$> unwrap xs) where go Nil = Nil - go (Cons x xs) = Cons (f x) (f <$> xs) + go (Cons x xs') = Cons (f x) (f <$> xs') instance foldableList :: Foldable List where foldr o b xs = go (step xs) @@ -111,24 +111,24 @@ instance foldableList :: Foldable List where foldMap f xs = go (step xs) where go Nil = mempty - go (Cons x xs) = f x <> foldMap f xs + go (Cons x xs') = f x <> foldMap f xs' instance unfoldableList :: Unfoldable List where unfoldr f b = go (f b) where go Nothing = nil - go (Just (Tuple a b)) = a : Z.defer \_ -> go (f b) + go (Just (Tuple a b')) = a : Z.defer \_ -> go (f b') instance traversableList :: Traversable List where traverse f xs = go (step xs) where go Nil = pure nil - go (Cons x xs) = cons <$> f x <*> traverse f xs + go (Cons x xs') = cons <$> f x <*> traverse f xs' sequence xs = go (step xs) where go Nil = pure nil - go (Cons x xs) = cons <$> x <*> sequence xs + go (Cons x xs') = cons <$> x <*> sequence xs' instance applyList :: Apply List where apply = ap @@ -140,7 +140,7 @@ instance bindList :: Bind List where bind xs f = List (go <$> unwrap xs) where go Nil = Nil - go (Cons x xs) = step (f x <> bind xs f) + go (Cons x xs') = step (f x <> bind xs' f) instance monadList :: Monad List diff --git a/src/Data/List/Types.purs b/src/Data/List/Types.purs index 6f32fa6..86b3ca1 100644 --- a/src/Data/List/Types.purs +++ b/src/Data/List/Types.purs @@ -35,7 +35,7 @@ instance eqList :: Eq a => Eq (List a) where where go _ _ false = false go Nil Nil acc = acc - go (x : xs) (y : ys) acc = go xs ys $ acc && (y == x) + go (x : xs') (y : ys') acc = go xs' ys' $ acc && (y == x) go _ _ _ = false instance ordList :: Ord a => Ord (List a) where @@ -44,9 +44,9 @@ instance ordList :: Ord a => Ord (List a) where go Nil Nil = EQ go Nil _ = LT go _ Nil = GT - go (x : xs) (y : ys) = + go (x : xs') (y : ys') = case compare x y of - EQ -> go xs ys + EQ -> go xs' ys' other -> other instance semigroupList :: Semigroup (List a) where @@ -111,8 +111,8 @@ instance extendList :: Extend List where extend f l@(a : as) = f l : (foldr go { val: Nil, acc: Nil } as).val where - go a { val, acc } = - let acc' = a : acc + go a' { val, acc } = + let acc' = a' : acc in { val: f acc' : val, acc: acc' } newtype NonEmptyList a = NonEmptyList (NonEmpty List a)