Package environments
[ghc.git] / compiler / utils / FiniteMap.hs
1 -- Some extra functions to extend Data.Map
2
3 module FiniteMap (
4 insertList,
5 insertListWith,
6 deleteList,
7 foldRight, foldRightWithKey
8 ) where
9
10 import Data.Map (Map)
11 import qualified Data.Map as Map
12
13 insertList :: Ord key => [(key,elt)] -> Map key elt -> Map key elt
14 insertList xs m = foldl (\m (k, v) -> Map.insert k v m) m xs
15
16 insertListWith :: Ord key
17 => (elt -> elt -> elt)
18 -> [(key,elt)]
19 -> Map key elt
20 -> Map key elt
21 insertListWith f xs m0 = foldl (\m (k, v) -> Map.insertWith f k v m) m0 xs
22
23 deleteList :: Ord key => [key] -> Map key elt -> Map key elt
24 deleteList ks m = foldl (flip Map.delete) m ks
25
26 foldRight :: (elt -> a -> a) -> a -> Map key elt -> a
27 foldRight = Map.fold
28 foldRightWithKey :: (key -> elt -> a -> a) -> a -> Map key elt -> a
29 foldRightWithKey = Map.foldrWithKey