map-exts 0.1.1.0 → 0.2.0.0
raw patch · 3 files changed
+34/−28 lines, 3 filesdep ~containersPVP ok
version bump matches the API change (PVP)
Dependency ranges changed: containers
API changes (from Hackage documentation)
- Data.Map.Extensions: drop :: Int -> Map k v -> Map k v
- Data.Map.Extensions: dropKeys :: Ord k => Set k -> Map k a -> Map k a
- Data.Map.Extensions: keepKeys :: Ord k => Set k -> Map k a -> Map k a
- Data.Map.Extensions: take :: Int -> Map k v -> Map k v
+ Data.Map.Extensions: dropLeft :: Int -> Map k v -> Map k v
+ Data.Map.Extensions: dropRight :: Int -> Map k v -> Map k v
+ Data.Map.Extensions: takeLeft :: Int -> Map k v -> Map k v
+ Data.Map.Extensions: takeRight :: Int -> Map k v -> Map k v
Files
- CHANGELOG.md +11/−0
- map-exts.cabal +2/−2
- src/Data/Map/Extensions.hs +21/−26
CHANGELOG.md view
@@ -1,3 +1,14 @@+0.2.0.0+Remove functions which are superseded by upstream++`containers` has added take, drop, restrictKeys and withoutKeys which are+equivalent to take, drop, keepKeys and dropKeys from the map-exts API,+respectively. takeLeft/Right and dropLeft/Right have been exposed.++containers:drop/take correspond to dropLeft and takeLeft respectively.++map-exts is now compatible with lts-10.3+ 0.1.1.0 Add version bound for upstream containers
map-exts.cabal view
@@ -1,5 +1,5 @@ name: map-exts-version: 0.1.1.0+version: 0.2.0.0 synopsis: Extensions to Data.Map description: Extensions to Data.Map homepage: http://github.com/charles-cooper/map-exts#readme@@ -26,7 +26,7 @@ other-modules: Data.Map.Function default-language: Haskell2010 build-depends: base >= 4.7 && < 5,- containers >= 0.5 && < 0.5.8.1+ containers >= 0.5.8.1 && < 0.6 executable example hs-source-dirs: examples, src main-is: Main.hs
src/Data/Map/Extensions.hs view
@@ -1,25 +1,24 @@ {-|- Module : Data.Map.Extensions- Description : Extensions to Data.Map- Copyright : (c) Elsen, Inc., 2016- License : BSD3- Maintainer : cooper.charles.m@gmail.com- Stability : experimental- Portability : portable+ Module : Data.Map.Extensions+ Description : Extensions to Data.Map+ Copyright : (c) Elsen, Inc., 2016+ License : BSD3+ Maintainer : cooper.charles.m@gmail.com+ Stability : experimental+ Portability : portable This module is a drop-in replacement for `Data.Map`. It is intended to be imported as @import qualified Data.Map.Extensions as Map@. -} module Data.Map.Extensions ( module Data.Map, - drop,- take,+ dropLeft,+ dropRight,+ takeLeft,+ takeRight, slice, slicei, - keepKeys,- dropKeys,- filterM, transpose, @@ -111,25 +110,29 @@ True -> empty False -> slice m lv rv -- O(log n) +-- O(n * log n). this could be O(log n) if we used Map.split cleverly.+-- | Drops `n` elements from the (left hand side of the) `Map`. dropLeft :: Int -> Map k v -> Map k v dropLeft n m | n <= 0 = m | Map.null m = m | otherwise = dropLeft (n-1) (deleteMin m) +-- O(n * log n). this could be O(log n) if we used Map.split cleverly.+-- | Drops `n` elements from the (right hand side of the) `Map`. dropRight :: Int -> Map k v -> Map k v dropRight n m | n <= 0 = m | Map.null m = m | otherwise = dropRight (n-1) (deleteMax m) -- O(n * log n). this could be O(log n) if we used Map.split cleverly.--- | Drops `n` elements from the (left hand side of the) `Map`.-drop :: Int -> Map k v -> Map k v-drop = dropLeft+-- | Takes `n` elements from the (left hand side of the) `Map`.+takeLeft :: Int -> Map k v -> Map k v+takeLeft n m = dropRight (Map.size m - n) m -- O(n * log n). this could be O(log n) if we used Map.split cleverly.--- | Takes `n` elements from the (left hand side of the) `Map`.-take :: Int -> Map k v -> Map k v-take n m = dropRight (Map.size m - n) m+-- | Takes `n` elements from the (right hand side of the) `Map`.+takeRight :: Int -> Map k v -> Map k v+takeRight n m = dropLeft (Map.size m - n) m -- | This generalizes `Map.filter` to a monadic predicate. filterM :: (Ord k, Monad m) => (v -> m Bool) -> Map k v -> m (Map k v)@@ -171,14 +174,6 @@ -- O(n * log(n)) groupBy :: Ord b => (a -> b) -> [a] -> Map b [a] groupBy f = fromListWith (++) . fmap (\a -> (f a, pure a))---- | Only keep keys that occur in the supplied `Set`.-keepKeys :: Ord k => Set k -> Map k a -> Map k a-keepKeys keys m = intersection m (fromSet (const ()) keys)---- | Drop the keys occurring in the supplied `Set`.-dropKeys :: Ord k => Set k -> Map k a -> Map k a-dropKeys keys m = m \\ (fromSet (const ()) keys) -- | Create a Map from a list of keys and a list of values. --