packages feed

data-stringmap 0.9 → 0.9.1

raw patch · 6 files changed

+32/−5 lines, 6 files

Files

Data/StringMap.hs view
@@ -70,6 +70,7 @@     , mapWithKey     , mapM     , mapWithKeyM+    , mapMaybe      -- * Folds     , fold
Data/StringMap/Base.hs view
@@ -91,6 +91,7 @@         , mapWithKey         , mapM         , mapWithKeyM+        , mapMaybe          -- * Folds         , fold@@ -133,7 +134,7 @@ import           Data.Binary import qualified Data.List      as L import qualified Data.Map       as M-import           Data.Maybe+import           Data.Maybe     hiding ( mapMaybe )  import           Data.StringMap.Types import           Data.StringMap.StringSet@@ -665,8 +666,23 @@ map' f k (LsVal c  v)           = LsVal  c  (f (k []) v) map' f k (BrVal c  v n)         = BrVal  c  (f (k []) v)             (map' f k n) --- ----------------------------------------+-- | /O(n)/ Updates a value or deletes the element if the result of the updating function is 'Nothing'. +mapMaybe                          :: (a -> Maybe b) -> StringMap a -> StringMap b+mapMaybe                          = mapMaybe'++{-# INLINE mapMaybe #-}++mapMaybe'                       :: (a -> Maybe b) -> StringMap a -> StringMap b+mapMaybe' f                     = upd . norm+    where+    upd'                        = mapMaybe' f+    upd (Branch c' s' n')       = branch c' (upd' s') (upd' n')+    upd Empty                   = empty+    upd (Val v' t')             = maybe t (flip val t) $ f v'+        where t = upd' t'+    upd _                       = normError "update'"+-- ---------------------------------------- {- not yet used  -- | Variant of map that works on normalized trees
Data/StringMap/Lazy.hs view
@@ -89,6 +89,7 @@     , mapWithKey     , mapM     , mapWithKeyM+    , mapMaybe      -- * Folds     , fold
Data/StringMap/Strict.hs view
@@ -90,6 +90,7 @@         , mapWithKey         , mapM         , mapWithKeyM+        , mapMaybe          -- * Folds         , fold
data-stringmap.cabal view
@@ -1,9 +1,9 @@ name:         data-stringmap-version:      0.9+version:      0.9.1 license:      MIT license-file: LICENSE-author:       Sebastian Philipp, Uwe Schmidt-maintainer:   uwe@fh-wedel.de+author:       Uwe Schmidt, Sebastian Philipp+maintainer:   uwe@fh-wedel.de, sebastian@spawnhost.de bug-reports:  https://github.com/sebastian-philipp/StringMap/issues synopsis:     An efficient implementation of maps from strings to arbitrary values category:     Data Structures
tests/StringMapProperties.hs view
@@ -50,6 +50,7 @@        , testCase "differenceWithKey" test_differenceWithKey        , testCase "map" test_map        , testCase "mapWithKey" test_mapWithKey+       , testCase "mapMaybe" test_mapMaybe        -- , testCase "mapM" test_mapM        -- , testCase "mapWithKeyM" test_mapWithKeyM        , testCase "fold" test_fold@@ -261,6 +262,13 @@ test_mapWithKey :: Assertion test_mapWithKey =     mapWithKey (mergeString "") (fromList [("a","A"), ("ab","B")]) @?= fromList [("ab", ":a|B"), ("a", ":a|A")]++test_mapMaybe :: Assertion+test_mapMaybe = do+    mapMaybe (Just . (* 10)) (fromList [("a",_1), ("ab",2)]) @?= fromList [("a", 10), ("ab", 20)]+    mapMaybe (f) (fromList [("a","A"), ("ab","B")]) @?= fromList [("a", 1::Int)]+    where+        f v = if v == "A" then Just 1 else Nothing  test_mapM :: Assertion test_mapM = undefined