appendmap 0.1.3 → 0.1.4
raw patch · 4 files changed
+41/−10 lines, 4 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
+ Data.Map.Counter: getCounts :: Counter key -> Map key Int
+ Data.Map.Counter: mkCounter :: Ord key => key -> Counter key
+ Data.Map.Counter: type Counter key = AppendMap key (Sum Int)
Files
- ChangeLog.md +2/−0
- appendmap.cabal +3/−2
- src/Data/Map/Counter.hs +15/−0
- test/Spec.hs +21/−8
ChangeLog.md view
@@ -2,6 +2,8 @@ ## Unreleased changes +## 0.1.4+ ## 0.1.3 * Fix tests on older LTS
appendmap.cabal view
@@ -2,10 +2,10 @@ -- -- see: https://github.com/sol/hpack ----- hash: 15eb223caaae1746fc5120f20c2e474df8b597f8c481c9d0dd3d8e2ebdd715fc+-- hash: da3c92d32d8763def130a63fd3d7770833e6f5a30a50b0a56e8d011019a440ec name: appendmap-version: 0.1.3+version: 0.1.4 synopsis: Map with a Semigroup and Monoid instances delegating to Semigroup of the elements description: Please see the README on GitHub at <https://github.com/koterpillar/appendmap#readme> category: Data Structures@@ -31,6 +31,7 @@ Data.Map.Append Data.Map.Append.Lazy Data.Map.Append.Strict+ Data.Map.Counter other-modules: Paths_appendmap hs-source-dirs:
+ src/Data/Map/Counter.hs view
@@ -0,0 +1,15 @@+module Data.Map.Counter where++import Data.Map.Append.Strict+import Data.Map.Strict (Map)+import qualified Data.Map.Strict as Map++import Data.Monoid++type Counter key = AppendMap key (Sum Int)++mkCounter :: Ord key => key -> Counter key+mkCounter key = AppendMap $ Map.singleton key (Sum 1)++getCounts :: Counter key -> Map key Int+getCounts = Map.map getSum . unAppendMap
test/Spec.hs view
@@ -1,6 +1,6 @@-{-# LANGUAGE AllowAmbiguousTypes #-}-{-# LANGUAGE RankNTypes #-}-{-# LANGUAGE RecordWildCards #-}+{-# LANGUAGE AllowAmbiguousTypes #-}+{-# LANGUAGE RankNTypes #-}+{-# LANGUAGE RecordWildCards #-} import qualified Data.Map.Append.Lazy as Lazy import qualified Data.Map.Lazy as Lazy@@ -8,6 +8,8 @@ import qualified Data.Map.Append.Strict as Strict import qualified Data.Map.Strict as Strict +import qualified Data.Map.Counter as Counter+ import Data.Semigroup import Test.Hspec@@ -46,15 +48,26 @@ => AppendMap appendmap map -> Spec appendMapSpec AppendMap {..} = do- it "has empty element" $- unAppendMap mempty `shouldBe` mapEmpty+ it "has empty element" $ unAppendMap mempty `shouldBe` mapEmpty it "combines elements" $ do let one = appendMap $ mapFromList [(1, "hello"), (2, "goodbye")] let two = appendMap $ mapFromList [(1, "world"), (3, "again")] unAppendMap (one <> two) `shouldBe` mapFromList [(1, "helloworld"), (2, "goodbye"), (3, "again")] +counterSpec :: Spec+counterSpec =+ it "counts entries" $ do+ let counted =+ Counter.mkCounter "one" <> Counter.mkCounter "two" <>+ Counter.mkCounter "two"+ let result = Counter.getCounts counted+ Strict.lookup "one" result `shouldBe` Just 1+ Strict.lookup "two" result `shouldBe` Just 2+ main :: IO ()-main = hspec $ do- describe "Data.Map.Append.Lazy" $ appendMapSpec lazy- describe "Data.Map.Append.Strict" $ appendMapSpec strict+main =+ hspec $ do+ describe "Data.Map.Append.Lazy" $ appendMapSpec lazy+ describe "Data.Map.Append.Strict" $ appendMapSpec strict+ describe "Data.Map.Counter" counterSpec