packages feed

classy-prelude 0.5.0 → 0.5.1

raw patch · 7 files changed

+38/−2 lines, 7 filesdep ~lifted-base

Dependency ranges changed: lifted-base

Files

ClassyPrelude.hs view
@@ -71,6 +71,7 @@     , sortWith     , cons     , uncons+    , compareLength       -- ** Map-like     , lookup     , insert
ClassyPrelude/Classes.hs view
@@ -194,3 +194,10 @@  class CanUncons c a where     uncons :: c -> Maybe (a, c)++class CanCompareLength c where+    -- | This is a more effective alternative to statements like @i >= length +    -- xs@ for types having an O(n) complexity of `length` operation like list +    -- or `Text`. It does not traverse the whole data structure if the value+    -- being compared to is lesser.+    compareLength :: (Integral l) => c -> l -> Ordering
ClassyPrelude/LText.hs view
@@ -122,3 +122,6 @@  instance CanUncons LText Char where     uncons = LText.uncons++instance CanCompareLength LText where+    compareLength c = LText.compareLength c . fromIntegral
ClassyPrelude/List.hs view
@@ -140,3 +140,9 @@ instance CanUncons [a] a where     uncons (head:tail) = Just (head, tail)     uncons _ = Nothing++instance CanCompareLength [a] where+    compareLength [] 0 = EQ+    compareLength _ i | i <= 0 = GT+    compareLength [] _ = LT+    compareLength (_:t) i = compareLength t (i-1)
ClassyPrelude/Text.hs view
@@ -114,3 +114,6 @@  instance CanUncons Text Char where     uncons = Text.uncons++instance CanCompareLength Text where+    compareLength c = Text.compareLength c . fromIntegral
classy-prelude.cabal view
@@ -1,5 +1,5 @@ name:                classy-prelude-version:             0.5.0+version:             0.5.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@@ -37,7 +37,7 @@                      , vector                      , unordered-containers                      , hashable-                     , lifted-base+                     , lifted-base                   >= 0.2   ghc-options:         -Wall -fno-warn-orphans  test-suite test
test/main.hs view
@@ -231,6 +231,18 @@     prop "decodeUtf8 . encodeUtf8 == id" $ \t ->         decodeUtf8 (encodeUtf8 t) == (t `asTypeOf` dummy) +compareLengthProps :: ( Show c+                      , Arbitrary c+                      , CanCompareLength c+                      , Show l+                      , Arbitrary l+                      , Integral l+                      , CanLength c l+                      ) => c -> Spec+compareLengthProps dummy = do+    prop "compare (length c) i == compareLength c i" $ \i c ->+        compare (length c) i == compareLength (c `asTypeOf` dummy) i+ main :: IO () main = hspec $ do     describe "dictionary" $ do@@ -315,6 +327,10 @@     describe "encode/decode UTF8" $ do         describe "Text" $ utf8Props (undefined :: Text)         describe "LText" $ utf8Props (undefined :: LText)+    describe "compareLength" $ do+        describe "list" $ compareLengthProps (undefined :: [Int])+        describe "Text" $ compareLengthProps (undefined :: Text)+        describe "LText" $ compareLengthProps (undefined :: LText)  instance Arbitrary (Map Int Char) where     arbitrary = fromList <$> arbitrary