NonEmptyList 0.0.5 → 0.0.6
raw patch · 3 files changed
+15/−12 lines, 3 filesdep +Semigroup
Dependencies added: Semigroup
Files
- Data/List/NonEmpty.hs +5/−8
- Data/List/ZipNonEmpty.hs +7/−1
- NonEmptyList.cabal +3/−3
Data/List/NonEmpty.hs view
@@ -12,7 +12,6 @@ toNonEmpty, unsafeToNonEmpty, (.:),- (.++), -- * List functions reverse, scanl,@@ -46,6 +45,7 @@ import Data.Traversable import Data.Typeable (Typeable) import Data.Data (Data)+import Data.Semigroup import qualified Data.List as L import Prelude hiding (foldr, reverse, scanl, scanl1, scanr, scanr1, iterate, repeat, cycle, zip, unzip) import Test.QuickCheck hiding (NonEmpty)@@ -79,6 +79,9 @@ instance (Show a) => Show (NonEmpty a) where show (NonEmpty h t) = '|' : show (h:t) ++ "|" +instance Semigroup (NonEmpty a) where+ NonEmpty a b .++. NonEmpty c d = NonEmpty a (b ++ c:d)+ -- | Constructs a non-empty list with the given head and tail. nonEmpty :: a -- ^ The head. -> [a] -- ^ The tail.@@ -109,12 +112,6 @@ -> NonEmpty a a .: NonEmpty h t = NonEmpty a (h:t) --- | Prepends a non-empty list to another non-empty list.-(.++) :: NonEmpty a -- ^ The non-empty list to prepend.- -> NonEmpty a -- ^ The non-empty list to prepend to.- -> NonEmpty a-NonEmpty a b .++ NonEmpty c d = NonEmpty a (b ++ c:d)- -- | Reverses the elements of the (finite) non-empty list. reverse :: NonEmpty a -> NonEmpty a@@ -206,7 +203,7 @@ prop_cons a as = toList (a .: as) == a : toList as prop_append :: NonEmpty String -> NonEmpty String -> Bool-prop_append a b = toList (a .++ b) == neHead a : neTail a ++ neHead b : neTail b+prop_append a b = toList (a .++. b) == neHead a : neTail a ++ neHead b : neTail b prop_reverse :: NonEmpty String -> Bool prop_reverse x = (reverse . reverse) x == x
Data/List/ZipNonEmpty.hs view
@@ -10,7 +10,10 @@ ) where import Data.List+import Data.Semigroup import Data.Foldable+import Data.Typeable (Typeable)+import Data.Data (Data) import Data.List.NonEmpty import Control.Applicative @@ -18,7 +21,7 @@ newtype ZipNonEmpty a = Z { -- | Unwraps a zip-like non-empty list. ne :: NonEmpty a-} deriving (Eq, Ord)+} deriving (Eq, Ord, Typeable, Data) -- | Wraps a non-empty list. zipNe :: NonEmpty a ->@@ -41,6 +44,9 @@ instance (Show a) => Show (ZipNonEmpty a) where show = show . ne++instance Semigroup (ZipNonEmpty a) where+ Z a .++. Z b = Z (a .++. b) instance Functor ZipNonEmpty where fmap = usingNe . fmap
NonEmptyList.cabal view
@@ -1,5 +1,5 @@ Name: NonEmptyList-Version: 0.0.5+Version: 0.0.6 License: BSD3 License-File: LICENSE Synopsis: A list with a length of at least one.@@ -17,9 +17,9 @@ Library if flag(small_base)- Build-Depends: base < 5 && >= 3, QuickCheck >= 2+ Build-Depends: base < 5 && >= 3, QuickCheck >= 2, Semigroup else- Build-Depends: base < 5 && >= 3, QuickCheck >= 2+ Build-Depends: base < 5 && >= 3, QuickCheck >= 2, Semigroup GHC-Options: -Wall Exposed-Modules: Data.List.NonEmpty