grouped-list 0.2.1.5 → 0.2.2.0
raw patch · 2 files changed
+13/−2 lines, 2 filesdep +binaryPVP ok
version bump matches the API change (PVP)
Dependencies added: binary
API changes (from Hackage documentation)
+ Data.GroupedList: instance Data.Binary.Class.Binary a => Data.Binary.Class.Binary (Data.GroupedList.Group a)
+ Data.GroupedList: instance Data.Binary.Class.Binary a => Data.Binary.Class.Binary (Data.GroupedList.Grouped a)
Files
- Data/GroupedList.hs +11/−1
- grouped-list.cabal +2/−1
Data/GroupedList.hs view
@@ -70,7 +70,9 @@ import Control.Arrow (second) import qualified Data.Map.Strict as M import Data.Functor.Identity (Identity (..))+import Control.Applicative (liftA2) import Control.Monad (foldM)+import Data.Binary (Binary (..)) ------------------------------------------------------------------ ------------------------------------------------------------------@@ -94,6 +96,10 @@ -- repeated a number of times. data Group a = Group {-# UNPACK #-} !Int a deriving Eq +instance Binary a => Binary (Group a) where+ put (Group n x) = put n *> put x+ get = liftA2 Group get get+ -- | Build a group by repeating the given element a number of times. -- If the given number is less or equal to 0, 'Nothing' is returned. buildGroup :: Int -> a -> Maybe (Group a)@@ -174,6 +180,10 @@ toList = toList #endif +instance Binary a => Binary (Grouped a) where+ put (Grouped xs) = put xs+ get = Grouped <$> get+ headGroup :: Eq a => [a] -> Maybe (Group a, [a]) headGroup [] = Nothing headGroup (a:as) = Just (Group n a, r)@@ -458,7 +468,7 @@ -- | Apply a function with results residing in an applicative functor to every -- element in a grouped list. traverseGrouped :: (Applicative f, Eq b) => (a -> f b) -> Grouped a -> f (Grouped b)-traverseGrouped f = foldr (\x fxs -> mappend <$> (point <$> f x) <*> fxs) (pure mempty)+traverseGrouped f = foldr (\x fxs -> liftA2 mappend (point <$> f x) fxs) (pure mempty) -- | Similar to 'traverseGrouped', but instead of applying a function to every element -- of the list, it is applied to groups of consecutive elements. You might return more
grouped-list.cabal view
@@ -1,5 +1,5 @@ name: grouped-list-version: 0.2.1.5+version: 0.2.2.0 synopsis: Grouped lists. Equal consecutive elements are grouped. description: Grouped lists work like regular lists, except for two conditions:@@ -32,6 +32,7 @@ , containers , pointed , deepseq+ , binary ghc-options: -O2 -Wall -- compatibility if impl(ghc < 7.10)