From 6a7e9e9595359945a67e346e0d26b505f3eb0b1e Mon Sep 17 00:00:00 2001 From: Tissevert Date: Wed, 3 Jun 2020 15:15:07 +0200 Subject: [PATCH] Expose a toList function similar to Data.Map in module Id for IdMap and allow mapping over keys and values in a monadic construct like mapM --- src/Data/Id.hs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/Data/Id.hs b/src/Data/Id.hs index 59ec8d4..f13cb6e 100644 --- a/src/Data/Id.hs +++ b/src/Data/Id.hs @@ -19,14 +19,15 @@ module Data.Id ( , register , singleton , size + , toList , union ) where import Control.Monad.State.Strict (MonadState, modify, gets) import Data.IntMap (IntMap, (!)) import qualified Data.IntMap as IntMap ( - delete, empty, filterWithKey, fromList, keysSet, insert, lookup - , mapWithKey, maxViewWithKey, member, minViewWithKey, size, union + delete, empty, filterWithKey, fromList, keysSet, insert, lookup, mapWithKey + , maxViewWithKey, member, minViewWithKey, size, toList, union ) import Data.IntSet (IntSet) import Prelude hiding (lookup) @@ -81,6 +82,9 @@ filterWithKey f = IdMap . IntMap.filterWithKey (f . Id) . intMap fromList :: [(Id a, b)] -> IdMap a b fromList = IdMap . IntMap.fromList . fmap (\(key, b) -> (getId key, b)) +toList :: IdMap a b -> [(Id a, b)] +toList = fmap (\(key, b) -> (Id key, b)) . IntMap.toList . intMap + keysSet :: IdMap a b -> IntSet keysSet = IntMap.keysSet . intMap