Permalink
Browse files

Add 'elems' and 'keys'

  • Loading branch information...
1 parent 8d8dcf0 commit 2722b58d92596bb18e8db30a00eb6a60842db712 @bovinespirit committed Oct 19, 2012
Showing with 36 additions and 1 deletion.
  1. +6 −0 Data/EnumMapMap/Base.hs
  2. +2 −0 Data/EnumMapMap/Lazy.hs
  3. +2 −0 Data/EnumMapMap/Strict.hs
  4. +6 −1 Data/EnumMapSet/Base.hs
  5. +20 −0 test/EnumMapMapVsIntMap.hs
@@ -246,6 +246,12 @@ class IsEmm k where
-- | Create a 'EnumMapMap' from a list of key\/value pairs.
fromList :: [(k, v)] -> EnumMapMap k v
fromList = foldlStrict (\t (k, x) -> insert k x t) empty
+ -- | List of elements in ascending order of keys
+ elems :: EnumMapMap k v -> [v]
+ elems = foldr (:) []
+ -- | List of keys
+ keys :: EnumMapMap k v -> [k]
+ keys = foldrWithKey (\k _ ks -> k:ks) []
-- | The (left-biased) union of two 'EnumMapMap's.
-- It prefers the first 'EnumMapMap' when duplicate keys are encountered.
union :: EnumMapMap k v -> EnumMapMap k v -> EnumMapMap k v
@@ -63,6 +63,8 @@ module Data.EnumMapMap.Lazy (
-- * Lists
toList,
fromList,
+ keys,
+ elems,
-- * Split/Join Keys
splitKey,
joinKey,
@@ -64,6 +64,8 @@ module Data.EnumMapMap.Strict (
-- * Lists
toList,
fromList,
+ keys,
+ elems,
-- * Split/Join Keys
splitKey,
joinKey,
@@ -39,6 +39,7 @@ module Data.EnumMapSet.Base (
-- * Lists
toList,
fromList,
+ keys,
-- * Internals
suffixBitMask,
prefixBitMask,
@@ -277,6 +278,7 @@ instance (Enum k) => IsEmm (K k) where
intersectionWithKey = undefined
fromList = undefined
toList = undefined
+ elems = undefined
{---------------------------------------------------------------------
Exported API
@@ -331,7 +333,7 @@ intersection :: (IsEmm k) => EnumMapSet k -> EnumMapSet k -> EnumMapSet k
intersection = EMM.intersection
{---------------------------------------------------------------------
- List
+ Lists
---------------------------------------------------------------------}
fromList :: IsEmm k => [k] -> EnumMapSet k
@@ -341,6 +343,9 @@ fromList xs
toList :: IsEmm k => EnumMapSet k -> [k]
toList = foldr (:) []
+keys :: IsEmm k => EnumMapSet k -> [k]
+keys = toList
+
{---------------------------------------------------------------------
Instances
---------------------------------------------------------------------}
@@ -417,3 +417,23 @@ main = hspec $ do
runPropDuoL4 (IM.intersectionWithKey f)
(EMM.intersectionWithKey
(\(k :& _ :& _ :& K _) a b -> f k a b))
+
+ describe "keys" $ do
+ prop "Level 1" $
+ runProp (IM.keys) (map (\(K k) -> k) . EMM.keys)
+ prop "Level 2" $
+ runProp2 (IM.keys) (map (\(k :& _) -> k) . EMM.keys)
+ prop "Level 3" $
+ runProp3 (IM.keys) (map (\(k :& _) -> k) . EMM.keys)
+ prop "Level 4" $
+ runProp4 (IM.keys) (map (\(k :& _) -> k) . EMM.keys)
+
+ describe "elems" $ do
+ prop "Level 1" $
+ runProp (IM.elems) (EMM.elems)
+ prop "Level 2" $
+ runProp2 (IM.elems) (EMM.elems)
+ prop "Level 3" $
+ runProp3 (IM.elems) (EMM.elems)
+ prop "Level 4" $
+ runProp4 (IM.elems) (EMM.elems)

0 comments on commit 2722b58

Please sign in to comment.