monoidal-containers 0.1.2.5 → 0.2.0.0
raw patch · 3 files changed
+45/−11 lines, 3 filesdep ~basedep ~containers
Dependency ranges changed: base, containers
Files
monoidal-containers.cabal view
@@ -1,5 +1,5 @@ name: monoidal-containers-version: 0.1.2.5+version: 0.2.0.0 synopsis: Containers with monoidal accumulation description: Containers with monoidal accumulation homepage: http://github.com/bgamari/monoidal-containers@@ -11,6 +11,7 @@ category: Data build-type: Simple cabal-version: >=1.10+tested-with: GHC ==7.4.2, GHC ==7.6.3, GHC ==7.8.4, GHC ==8.0.1 source-repository head type: git@@ -24,9 +25,9 @@ GeneralizedNewtypeDeriving, DeriveTraversable, DeriveDataTypeable- build-depends: base >=4.7 && <4.10,+ build-depends: base >=4.5 && <4.10, deepseq >=1.3 && <1.5,- containers >=0.5 && <0.6,+ containers >=0.4 && <0.6, unordered-containers >= 0.2 && < 0.3, hashable >= 1.2 && < 1.3, lens >=4.4 && <5,
src/Data/HashMap/Monoidal.hs view
@@ -12,12 +12,14 @@ -- -- While some functions mirroring those of 'Data.HashMap' are provided -- here for convenience, more specialized needs will likely want to use--- either the @Newtype@ or @Wrapped@ instances to manipulate the+-- either the 'Newtype' or 'Wrapped' instances to manipulate the -- underlying 'Map'. module Data.HashMap.Monoidal ( MonoidalHashMap -- * Often-needed functions+ , toList+ , fromList , singleton , size , member@@ -30,9 +32,11 @@ , mapKeys , modify , modifyDef+ , map+ , filterWithKey ) where -import Prelude hiding (lookup)+import Prelude hiding (lookup, map) import Data.Maybe (fromMaybe) import Data.Monoid import Data.Foldable (Foldable)@@ -41,7 +45,7 @@ import Data.Typeable (Typeable) #if MIN_VERSION_base(4,7,0)-import GHC.Exts (IsList(..))+import qualified GHC.Exts as Exts #endif import Control.DeepSeq@@ -101,7 +105,7 @@ {-# INLINE unpack #-} #if MIN_VERSION_base(4,7,0)-instance (Eq k, Hashable k, Monoid a) => IsList (MonoidalHashMap k a) where+instance (Eq k, Hashable k, Monoid a) => Exts.IsList (MonoidalHashMap k a) where type Item (MonoidalHashMap k a) = (k, a) fromList = MM . M.fromListWith mappend {-# INLINE fromList #-}@@ -160,6 +164,18 @@ keys = M.keys . unpack {-# INLINE keys #-} +-- | /O(n*log n)/. Construct a map with the supplied mappings. If the list+-- contains duplicate mappings, the later mappings take precedence.+fromList :: (Eq k, Hashable k) => [(k,a)] -> MonoidalHashMap k a+fromList = pack . M.fromList+{-# INLINE fromList #-}++-- | /O(n*log n)/. Construct a map with the supplied mappings. If the list+-- contains duplicate mappings, the later mappings take precedence.+toList :: MonoidalHashMap k a -> [(k,a)]+toList = M.toList . unpack+{-# INLINE toList #-}+ -- | /O(log n)/. Modify a value on some key with a function, if value -- under key doesn't exist -- use mempty. modify :: (Monoid a, Hashable k, Eq k)@@ -184,8 +200,19 @@ -- | /O(n)/. Map a function to each key of a map mapKeys :: (Monoid a, Hashable k, Eq k, Hashable k', Eq k')- => (k -> k') -> MonoidalHashMap k a- -> MonoidalHashMap k' a+ => (k -> k') -> MonoidalHashMap k a -> MonoidalHashMap k' a mapKeys f = fromList- . map (\(k, v) -> (f k, v))+ . fmap (\(k, v) -> (f k, v)) . toList+{-# INLINE mapKeys #-}++-- | /O(n)/ Filter this map by retaining only elements satisfying a+-- predicate.+filterWithKey :: (k -> v -> Bool) -> MonoidalHashMap k v -> MonoidalHashMap k v+filterWithKey pred = pack . M.filterWithKey pred . unpack+{-# INLINE filterWithKey #-}++-- | /O(n)/ Transform this map by applying a function to every value.+map :: (v1 -> v2) -> MonoidalHashMap k v1 -> MonoidalHashMap k v2+map f = pack . M.map f . unpack+{-# INLINE map #-}
src/Data/Map/Monoidal.hs view
@@ -12,7 +12,7 @@ -- -- While some functions mirroring those of 'Data.Map' are provided -- here for convenience, more specialized needs will likely want to use--- either the @Newtype@ or @Wrapped@ instances to manipulate the+-- either the 'Newtype' or 'Wrapped' instances to manipulate the -- underlying 'Map'. module Data.Map.Monoidal@@ -23,6 +23,7 @@ , member , notMember , findWithDefault+ , assocs , elems , keys ) where@@ -141,6 +142,11 @@ delete :: Ord k => k -> MonoidalMap k a -> MonoidalMap k a delete k = _Wrapping' MM %~ M.delete k {-# INLINE delete #-}++-- | /O(n)/. Return all elements of the map and their keys+assocs :: MonoidalMap k a -> [(k,a)]+assocs = M.assocs . unpack+{-# INLINE assocs #-} -- | /O(n)/. Return all elements of the map in the ascending order of their -- keys. Subject to list fusion.