summaryrefslogtreecommitdiff
path: root/compiler/utils/FiniteMap.hs
blob: dccfca10a9a8eb844c9819acb915987a825a1ce4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
-- Some extra functions to extend Data.Map

module FiniteMap (
        insertList,
        insertListWith,
        deleteList,
        foldRight, foldRightWithKey
    ) where

import Data.Map (Map)
import qualified Data.Map as Map

insertList :: Ord key => [(key,elt)] -> Map key elt -> Map key elt
insertList xs m = foldl (\m (k, v) -> Map.insert k v m) m xs

insertListWith :: Ord key
               => (elt -> elt -> elt)
               -> [(key,elt)]
               -> Map key elt
               -> Map key elt
insertListWith f xs m0 = foldl (\m (k, v) -> Map.insertWith f k v m) m0 xs

deleteList :: Ord key => [key] -> Map key elt -> Map key elt
deleteList ks m = foldl (flip Map.delete) m ks

foldRight        :: (elt -> a -> a) -> a -> Map key elt -> a
foldRight        = Map.fold
foldRightWithKey :: (key -> elt -> a -> a) -> a -> Map key elt -> a
foldRightWithKey = Map.foldrWithKey