NonEmptyList 0.0.2 → 0.0.3
raw patch · 2 files changed
+20/−11 lines, 2 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
+ Data.List.NonEmpty: fromNonEmpty :: NonEmpty a -> [a]
+ Data.List.NonEmpty: instance (Data a) => Data (NonEmpty a)
+ Data.List.NonEmpty: instance Typeable1 NonEmpty
Files
- Data/List/NonEmpty.hs +18/−9
- NonEmptyList.cabal +2/−2
Data/List/NonEmpty.hs view
@@ -1,9 +1,12 @@+{-# LANGUAGE DeriveDataTypeable #-}+ -- | A type-safe list that has at least one element. module Data.List.NonEmpty( NonEmpty, -- * Accessors neHead, neTail,+ fromNonEmpty, -- * Constructors nonEmpty, (|:),@@ -23,7 +26,7 @@ tails, sort, insert,- unzip, + unzip, -- * Tests prop_neHead, prop_neTail,@@ -42,6 +45,8 @@ import Data.Foldable import Data.Maybe import Data.Traversable+import Data.Typeable (Typeable)+import Data.Data (Data) 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)@@ -50,7 +55,7 @@ data NonEmpty a = NonEmpty { neHead :: a, -- ^ The head of the non-empty list. neTail :: [a] -- ^ The tail of the non-empty list.-} deriving (Eq, Ord)+} deriving (Eq, Ord, Typeable, Data) instance Functor NonEmpty where fmap f (NonEmpty h t) = NonEmpty (f h) (fmap f t)@@ -62,7 +67,7 @@ instance Monad NonEmpty where return = flip NonEmpty [] NonEmpty h t >>= f = let NonEmpty a b = f h- k = t >>= toList . f+ k = t >>= fromNonEmpty . f in NonEmpty a (b ++ k) instance Foldable NonEmpty where@@ -70,11 +75,15 @@ foldl f x (NonEmpty h t) = foldl' f x (h:t) instance Traversable NonEmpty where- traverse f a = NonEmpty <$> head <*> tail <$> traverse f (toList a)+ traverse f a = NonEmpty <$> head <*> tail <$> traverse f (fromNonEmpty a) instance (Show a) => Show (NonEmpty a) where show (NonEmpty h t) = '|' : show (h:t) ++ "|" +-- | Conversion to ordinary list (like Data.Foldable.toList, but O(1)).+fromNonEmpty :: NonEmpty a -> [a]+fromNonEmpty (NonEmpty x y) = x : y+ -- | Constructs a non-empty list with the given head and tail. nonEmpty :: a -- ^ The head. -> [a] -- ^ The tail.@@ -165,11 +174,11 @@ a -> NonEmpty a -> NonEmpty a-insert a = unsafeToNonEmpty . L.insert a . toList+insert a = unsafeToNonEmpty . L.insert a . fromNonEmpty unzip :: NonEmpty (a, b) -> (NonEmpty a, NonEmpty b)-unzip = (unsafeToNonEmpty *** unsafeToNonEmpty) . L.unzip . toList+unzip = (unsafeToNonEmpty *** unsafeToNonEmpty) . L.unzip . fromNonEmpty ----------- -- TESTS --@@ -177,7 +186,7 @@ instance (Arbitrary a) => Arbitrary (NonEmpty a) where arbitrary = nonEmpty <$> arbitrary <*> arbitrary- shrink = (unsafeToNonEmpty <$>) . shrink . toList+ shrink = (unsafeToNonEmpty <$>) . shrink . fromNonEmpty prop_neHead :: String -> [String] -> Bool prop_neHead h t = neHead (nonEmpty h t) == h@@ -199,10 +208,10 @@ prop_unsafeNonEmpty x = not (null x) ==> prop_toNonEmpty x prop_cons :: String -> NonEmpty String -> Bool-prop_cons a as = toList (a .: as) == a : toList as+prop_cons a as = fromNonEmpty (a .: as) == a : fromNonEmpty 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 = fromNonEmpty (a .++ b) == neHead a : neTail a ++ neHead b : neTail b prop_reverse :: NonEmpty String -> Bool prop_reverse x = (reverse . reverse) x == x
NonEmptyList.cabal view
@@ -1,12 +1,12 @@ Name: NonEmptyList-Version: 0.0.2+Version: 0.0.3 License: BSD3 License-File: LICENSE Synopsis: A list with a length of at least one. Description: A list with a length of at least one and type-safe head/tail operations. Homepage: http://code.google.com/p/nonempty/ Category: Data-Author: Tony Morris, Oliver Taylor+Author: Tony Morris, Oliver Taylor, Eelis van der Weegen Maintainer: code@tmorris.net Copyright: 2010 Tony Morris, Oliver Taylor build-type: Simple