int-like 0.1.0 → 0.1.1
raw patch · 3 files changed
+13/−1 lines, 3 files
Files
- README.md +2/−0
- int-like.cabal +1/−1
- src/IntLike/Map.hs +10/−0
README.md view
@@ -3,3 +3,5 @@ [](https://circleci.com/gh/ejconlon/int-like/tree/master) Newtype wrappers over `IntSet` and `IntMap`++Never mix up `Int` newtypes again! Instead of working directly with an `IntSet`, you can work with `IntLikeSet MyIntNewtype` with more or less the same API. You might have to thread through some `Coercible` constraints, though.
int-like.cabal view
@@ -5,7 +5,7 @@ -- see: https://github.com/sol/hpack name: int-like-version: 0.1.0+version: 0.1.1 synopsis: Newtype wrappers over IntSet and IntMap description: Please see the README on GitHub at <https://github.com/ejconlon/int-like#readme> category: Data Structures
src/IntLike/Map.hs view
@@ -8,6 +8,7 @@ , member , toList , keys+ , keysSet , elems , lookup , partialLookup@@ -22,6 +23,7 @@ , restrictKeys , map , insertState+ , mapWithKey ) where import Control.DeepSeq (NFData)@@ -67,6 +69,10 @@ keys = coerce . IntMap.keys . unIntLikeMap {-# INLINE keys #-} +keysSet :: IntLikeMap x a -> IntLikeSet x+keysSet = IntLikeSet . IntMap.keysSet . unIntLikeMap+{-# INLINE keysSet #-}+ elems :: IntLikeMap x a -> [a] elems = IntMap.elems . unIntLikeMap {-# INLINE elems #-}@@ -122,3 +128,7 @@ insertState :: Coercible x Int => (Maybe a -> b) -> x -> a -> IntLikeMap x a -> (b, IntLikeMap x a) insertState f x a = coerce . IntMap.alterF (\m -> (f m, Just a)) (coerce x) . unIntLikeMap {-# INLINE insertState #-}++mapWithKey :: Coercible x Int => (x -> a -> b) -> IntLikeMap x a -> IntLikeMap x b+mapWithKey f = IntLikeMap . IntMap.mapWithKey (coerce f) . unIntLikeMap+{-# INLINE mapWithKey #-}