classy-prelude 0.5.9 → 0.5.10
raw patch · 5 files changed
+28/−12 lines, 5 filesPVP: major bump suggested
API removals or changes: PVP suggests a major version bump
API changes (from Hackage documentation)
- ClassyPrelude.Classes: class CanReplicateM_ i len
- ClassyPrelude.Classes: replicateM_ :: (CanReplicateM_ i len, Monad m) => len -> m i -> m ()
+ ClassyPrelude: group' :: CanGroup' c a => c -> [c]
+ ClassyPrelude: groupBy' :: CanGroupBy' c a => (a -> a -> Bool) -> c -> [c]
+ ClassyPrelude.Classes: class CanGroup' c a | c -> a where group' = groupBy' (==)
+ ClassyPrelude.Classes: class CanGroupBy' c a | c -> a
+ ClassyPrelude.Classes: group' :: CanGroup' c a => c -> [c]
+ ClassyPrelude.Classes: groupBy' :: CanGroupBy' c a => (a -> a -> Bool) -> c -> [c]
- ClassyPrelude: groupWith :: (CanGroupBy c a, Eq b) => (a -> b) -> c -> [c]
+ ClassyPrelude: groupWith :: (CanGroupBy' c a, Eq b) => (a -> b) -> c -> [c]
- ClassyPrelude: replicateM_ :: (CanReplicateM_ i len, Monad m) => len -> m i -> m ()
+ ClassyPrelude: replicateM_ :: Monad m => Int -> m a -> m ()
Files
- ClassyPrelude.hs +5/−3
- ClassyPrelude/Classes.hs +12/−3
- ClassyPrelude/List.hs +8/−3
- classy-prelude.cabal +1/−1
- test/main.hs +2/−2
ClassyPrelude.hs view
@@ -83,7 +83,9 @@ , sortBy , sortWith , group+ , group' , groupBy+ , groupBy' , groupWith , cons , uncons@@ -150,7 +152,7 @@ ) where import qualified Prelude-import Control.Monad (when, unless, void, liftM, ap, forever, join, sequence, sequence_)+import Control.Monad (when, unless, void, liftM, ap, forever, join, sequence, sequence_, replicateM_) import Control.Monad.Trans.Control (MonadBaseControl, liftBaseWith, restoreM) import Control.Concurrent.Async (withAsync, waitCatch) import Control.Concurrent.MVar.Lifted@@ -300,8 +302,8 @@ -- input list and then to form groups by equality on these projected elements -- -- Inspired by <http://hackage.haskell.org/packages/archive/base/latest/doc/html/GHC-Exts.html#v:groupWith>-groupWith :: (CanGroupBy c a, Eq b) => (a -> b) -> c -> [c]-groupWith f = groupBy (\a b -> f a == f b)+groupWith :: (CanGroupBy' c a, Eq b) => (a -> b) -> c -> [c]+groupWith f = groupBy' (\a b -> f a == f b) -- | We define our own @undefined@ which is marked as deprecated. This makes it -- useful to use during development, but let's you more easily getting
ClassyPrelude/Classes.hs view
@@ -51,9 +51,6 @@ class CanReplicateM c i len | c -> i len where replicateM :: Monad m => len -> m i -> m c -class CanReplicateM_ i len where- replicateM_ :: Monad m => len -> m i -> m ()- class CanLookup c k v | c -> k v where lookup :: k -> c -> Maybe v @@ -210,10 +207,22 @@ class CanGroupBy c a | c -> a where groupBy :: (a -> a -> Bool) -> c -> [c] +class CanGroupBy' c a | c -> a where+ -- | Similar to standard 'groupBy', but operates on the whole collection, + -- not just the consecutive items.+ groupBy' :: (a -> a -> Bool) -> c -> [c]+ class CanGroup c a | c -> a where group :: c -> [c] default group :: (CanGroupBy c a, Eq a) => c -> [c] group = groupBy (==)++class CanGroup' c a | c -> a where+ -- | Similar to standard 'group', but operates on the whole collection, + -- not just the consecutive items.+ group' :: c -> [c]+ default group' :: (CanGroupBy' c a, Eq a) => c -> [c]+ group' = groupBy' (==) class CanRepeat c a | c -> a where repeat :: a -> c
ClassyPrelude/List.hs view
@@ -102,9 +102,6 @@ instance CanReplicateM [a] a Int where replicateM = Monad.replicateM -instance CanReplicateM_ a Int where- replicateM_ = Monad.replicateM_- instance CanFind [a] a where find = List.find @@ -155,8 +152,16 @@ instance CanGroupBy [a] a where groupBy = List.groupBy +instance CanGroupBy' [a] a where+ groupBy' f (head : tail) = let+ (matches, nonMatches) = partition (f head) tail+ in (head : matches) : groupBy' f nonMatches+ groupBy' _ [] = []+ instance Eq a => CanGroup [a] a where group = List.group++instance Eq a => CanGroup' [a] a instance CanRepeat [a] a where repeat = List.repeat
classy-prelude.cabal view
@@ -1,5 +1,5 @@ name: classy-prelude-version: 0.5.9+version: 0.5.10 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
test/main.hs view
@@ -7,10 +7,10 @@ {-# OPTIONS_GHC -fno-warn-orphans #-} import Test.Hspec import Test.Hspec.QuickCheck-import ClassyPrelude+import ClassyPrelude hiding (undefined) import ClassyPrelude.Classes import Test.QuickCheck.Arbitrary-import Prelude (asTypeOf, fromIntegral)+import Prelude (asTypeOf, fromIntegral, undefined) import qualified Prelude import Control.Monad.Trans.Writer (tell, Writer, runWriter) import Data.Maybe (isJust)