classy-prelude 0.3.0 → 0.3.1
raw patch · 6 files changed
+78/−4 lines, 6 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
+ ClassyPrelude: asByteString :: ByteString -> ByteString
+ ClassyPrelude: asHashMap :: HashMap k v -> HashMap k v
+ ClassyPrelude: asHashSet :: HashSet a -> HashSet a
+ ClassyPrelude: asLByteString :: LByteString -> LByteString
+ ClassyPrelude: asLText :: LText -> LText
+ ClassyPrelude: asList :: [a] -> [a]
+ ClassyPrelude: asMap :: Map k v -> Map k v
+ ClassyPrelude: asSet :: Set a -> Set a
+ ClassyPrelude: asText :: Text -> Text
+ ClassyPrelude: asVector :: Vector a -> Vector a
+ ClassyPrelude: fromChunks :: CanToChunks c i => [i] -> c
+ ClassyPrelude: toChunks :: CanToChunks c i => c -> [i]
+ ClassyPrelude.Classes: class CanToChunks c i | c -> i, i -> c
+ ClassyPrelude.Classes: fromChunks :: CanToChunks c i => [i] -> c
+ ClassyPrelude.Classes: toChunks :: CanToChunks c i => c -> [i]
Files
- ClassyPrelude.hs +44/−0
- ClassyPrelude/Classes.hs +4/−0
- ClassyPrelude/LByteString.hs +5/−0
- ClassyPrelude/LText.hs +5/−0
- classy-prelude.cabal +2/−2
- test/main.hs +18/−2
ClassyPrelude.hs view
@@ -59,6 +59,20 @@ -- ** Files , readFile , writeFile+ -- ** Chunking+ , toChunks+ , fromChunks+ -- ** Force types+ , asByteString+ , asLByteString+ , asHashMap+ , asHashSet+ , asText+ , asLText+ , asList+ , asMap+ , asSet+ , asVector ) where import qualified Prelude@@ -122,3 +136,33 @@ (++) :: Monoid m => m -> m -> m (++) = mappend {-# INLINE (++) #-}++asByteString :: ByteString -> ByteString+asByteString = id++asLByteString :: LByteString -> LByteString+asLByteString = id++asHashMap :: HashMap k v -> HashMap k v+asHashMap = id++asHashSet :: HashSet a -> HashSet a+asHashSet = id++asText :: Text -> Text+asText = id++asLText :: LText -> LText+asLText = id++asList :: [a] -> [a]+asList = id++asMap :: Map k v -> Map k v+asMap = id++asSet :: Set a -> Set a+asSet = id++asVector :: Vector a -> Vector a+asVector = id
ClassyPrelude/Classes.hs view
@@ -136,3 +136,7 @@ class CanReplicate a i len | a -> i len where replicate :: len -> i -> a++class CanToChunks c i | c -> i, i -> c where+ toChunks :: c -> [i]+ fromChunks :: [i] -> c
ClassyPrelude/LByteString.hs view
@@ -14,6 +14,7 @@ import qualified Filesystem.Path.CurrentOS as F import Data.Word (Word8) import Data.Int (Int64)+import qualified Data.ByteString type LByteString = L.ByteString @@ -55,3 +56,7 @@ instance CanReplicate LByteString Word8 Int64 where replicate = L.replicate++instance CanToChunks LByteString Data.ByteString.ByteString where+ toChunks = L.toChunks+ fromChunks = L.fromChunks
ClassyPrelude/LText.hs view
@@ -11,6 +11,7 @@ import ClassyPrelude.Classes import qualified Data.Text.Lazy as TL import Data.Int (Int64)+import qualified Data.Text type LText = TL.Text @@ -68,3 +69,7 @@ instance CanReplicate LText LText Int64 where replicate = TL.replicate++instance CanToChunks LText Data.Text.Text where+ toChunks = TL.toChunks+ fromChunks = TL.fromChunks
classy-prelude.cabal view
@@ -1,5 +1,5 @@ name: classy-prelude-version: 0.3.0+version: 0.3.1 synopsis: A typeclass-based Prelude. description: Focuses on using common typeclasses when possible, and creating new ones to avoid name clashing. Exposes many recommended datastructures (Map, ByteString, etc) directly without requiring long import lists and qualified modules. homepage: https://github.com/snoyberg/classy-prelude@@ -7,7 +7,7 @@ license-file: LICENSE author: Michael Snoyman maintainer: michael@snoyman.com-category: Control+category: Control, Prelude build-type: Simple cabal-version: >=1.8
test/main.hs view
@@ -20,6 +20,7 @@ , Arbitrary a , Monoid a , CanLookup a Int Char+ , CanPack a (Int, Char) ) => a -> Spec dictionaryProps dummy = do@@ -28,7 +29,7 @@ prop "insert x y (delete x c) == insert x y c" $ \x y c -> insert x y (delete x (c `asTypeOf` dummy)) == insert x y c prop "delete x (insert x y c) == delete x c" $ \x y c ->- delete x (insert x y (c `asTypeOf` dummy)) == delete x c+ pack (unpack $ delete x (insert x y (c `asTypeOf` dummy))) == (pack (unpack ((delete x c) `asTypeOf` dummy) :: [(Int, Char)]) `asTypeOf` dummy) prop "lookup k (insert k v empty) == Just v" $ \k v -> lookup k (insert k v empty `asTypeOf` dummy) == Just v prop "lookup k (delete k c) == Nothing" $ \k c ->@@ -87,7 +88,7 @@ -> Spec filterProps dummy f = do prop "filter f c == pack (filter f (unpack c))" $ \c ->- filter f (c `asTypeOf` dummy) == pack (filter f (unpack c))+ (repack (filter f (c `asTypeOf` dummy)) `asTypeOf` dummy) == pack (filter f (unpack c)) lengthProps :: ( Show a , Eq a@@ -165,6 +166,18 @@ where i = 3 +chunkProps :: ( Eq a+ , Show a+ , Arbitrary a+ , CanToChunks a i+ , Monoid i+ ) => a -> Spec+chunkProps dummy = do+ prop "fromChunks . toChunks == id" $ \a ->+ fromChunks (toChunks (a `asTypeOf` dummy)) == a+ prop "fromChunks . return . concat . toChunks == id" $ \a ->+ fromChunks [concat $ toChunks (a `asTypeOf` dummy)] == a+ main :: IO () main = hspec $ do describe "dictionary" $ do@@ -230,6 +243,9 @@ describe "Data.ByteString.Lazy" $ replicateProps (undefined :: LByteString) pack describe "Data.Text" $ replicateProps (undefined :: Text) concat describe "Data.Text.Lazy" $ replicateProps (undefined :: LText) concat+ describe "chunks" $ do+ describe "ByteString" $ chunkProps (asLByteString undefined)+ describe "Text" $ chunkProps (asLText undefined) instance Arbitrary (Map Int Char) where arbitrary = fromList <$> arbitrary