packages feed

grouped-list 0.2.1.4 → 0.2.1.5

raw patch · 4 files changed

+21/−6 lines, 4 filesPVP: major bump suggested

API removals or changes: PVP suggests a major version bump

API changes (from Hackage documentation)

- Data.GroupedList: length :: Foldable t => forall a. t a -> Int
+ Data.GroupedList: length :: Foldable t => forall a. () => t a -> Int
- Data.GroupedList: point :: Pointed p => forall a. a -> p a
+ Data.GroupedList: point :: Pointed p => forall a. () => a -> p a

Files

Data/GroupedList.hs view
@@ -63,7 +63,6 @@ import qualified Prelude as Prelude import Data.Pointed import Data.Foldable (Foldable (..), toList)-import Data.List (group) import Data.Sequence (Seq) import qualified Data.Sequence as S import Data.Monoid ((<>))@@ -158,8 +157,8 @@ -- GROUPED  -- | Type of grouped lists. Grouped lists are finite lists that---   behave well in the abundance of sublists that have all their---   elements equal.+--   perform better than regular lists in the abundance of sublists+--   that have all their elements equal. newtype Grouped a = Grouped (Seq (Group a)) deriving Eq  -- | Grouped list with no elements.@@ -175,10 +174,22 @@   toList = toList #endif +headGroup :: Eq a => [a] -> Maybe (Group a, [a])+headGroup [] = Nothing+headGroup (a:as) = Just (Group n a, r)+  where+    (n,r) = count 1 as+    count acc [] = (acc,[])+    count acc l@(x:xs) =+      if a == x+         then let acc' = acc + 1+              in  seq acc' $ count acc' xs+         else (acc, l)+ -- | Build a grouped list from a regular list. It doesn't work if --   the input list is infinite. fromList :: Eq a => [a] -> Grouped a-fromList = Grouped . S.fromList . fmap (\g -> Group (Prelude.length g) $ head g) . group+fromList = Grouped . S.unfoldr headGroup  -- | Build a grouped list from a group (see 'Group'). fromGroup :: Group a -> Grouped a
bench/Main.hs view
@@ -11,7 +11,7 @@ import Criterion.Types (reportFile)  sampleSize :: Int-sampleSize = 1000+sampleSize = 2000  sampleSize2 :: Int sampleSize2 = div sampleSize 2@@ -59,4 +59,6 @@   , benchGroup "adjust 2/2" $ nf $ G.adjust (+1) $ sampleSize - 1   , bench "mappend" $ nf (\xs -> mappend xs xs) halflist   , benchGroup "sort" $ nf G.sort+  , bench "fromList/uniform" $ nf G.fromList (replicate sampleSize (0 :: Int))+  , bench "fromList/increasing" $ nf G.fromList [1..sampleSize]     ]
grouped-list.cabal view
@@ -1,5 +1,5 @@ name:                grouped-list-version:             0.2.1.4+version:             0.2.1.5 synopsis:            Grouped lists. Equal consecutive elements are grouped. description:   Grouped lists work like regular lists, except for two conditions:
test/properties.hs view
@@ -50,4 +50,6 @@       \(G xs) -> GL.map (+1) (GL.map (+1) xs) == GL.map (+2) xs   , prop "'map (const i)' generates at most one group" $       \(G xs) i -> length (GL.groupedGroups $ GL.map (const i) xs :: [GL.Group Int]) <= 1+  , prop "fromList . toList = id" $ \(G xs) -> GL.fromList (toList xs) == xs+  , prop "toList . fromList = id" $ \xs -> toList (GL.fromList xs) == (xs :: [Int])     ]