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

This commit is contained in:
Tissevert 2020-06-03 15:15:07 +02:00
parent d9f69014a0
commit 6a7e9e9595
1 changed files with 6 additions and 2 deletions

View File

@ -19,14 +19,15 @@ module Data.Id (
, register , register
, singleton , singleton
, size , size
, toList
, union , union
) where ) where
import Control.Monad.State.Strict (MonadState, modify, gets) import Control.Monad.State.Strict (MonadState, modify, gets)
import Data.IntMap (IntMap, (!)) import Data.IntMap (IntMap, (!))
import qualified Data.IntMap as IntMap ( import qualified Data.IntMap as IntMap (
delete, empty, filterWithKey, fromList, keysSet, insert, lookup delete, empty, filterWithKey, fromList, keysSet, insert, lookup, mapWithKey
, mapWithKey, maxViewWithKey, member, minViewWithKey, size, union , maxViewWithKey, member, minViewWithKey, size, toList, union
) )
import Data.IntSet (IntSet) import Data.IntSet (IntSet)
import Prelude hiding (lookup) import Prelude hiding (lookup)
@ -81,6 +82,9 @@ filterWithKey f = IdMap . IntMap.filterWithKey (f . Id) . intMap
fromList :: [(Id a, b)] -> IdMap a b fromList :: [(Id a, b)] -> IdMap a b
fromList = IdMap . IntMap.fromList . fmap (\(key, b) -> (getId key, 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 :: IdMap a b -> IntSet
keysSet = IntMap.keysSet . intMap keysSet = IntMap.keysSet . intMap