-- Some extra functions to extend Data.Map

module GHC.Data.FiniteMap (
        insertList,
        insertListWith,
        deleteList,
        foldRight, foldRightWithKey
    ) where

import GHC.Prelude

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

insertList :: Ord key => [(key,elt)] -> Map key elt -> Map key elt
insertList :: forall key elt.
Ord key =>
[(key, elt)] -> Map key elt -> Map key elt
insertList [(key, elt)]
xs Map key elt
m = forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
foldl' (\Map key elt
m (key
k, elt
v) -> forall k a. Ord k => k -> a -> Map k a -> Map k a
Map.insert key
k elt
v Map key elt
m) Map key elt
m [(key, elt)]
xs

insertListWith :: Ord key
               => (elt -> elt -> elt)
               -> [(key,elt)]
               -> Map key elt
               -> Map key elt
insertListWith :: forall key elt.
Ord key =>
(elt -> elt -> elt) -> [(key, elt)] -> Map key elt -> Map key elt
insertListWith elt -> elt -> elt
f [(key, elt)]
xs Map key elt
m0 = forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
foldl' (\Map key elt
m (key
k, elt
v) -> forall k a. Ord k => (a -> a -> a) -> k -> a -> Map k a -> Map k a
Map.insertWith elt -> elt -> elt
f key
k elt
v Map key elt
m) Map key elt
m0 [(key, elt)]
xs

deleteList :: Ord key => [key] -> Map key elt -> Map key elt
deleteList :: forall key elt. Ord key => [key] -> Map key elt -> Map key elt
deleteList [key]
ks Map key elt
m = forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
foldl' (forall a b c. (a -> b -> c) -> b -> a -> c
flip forall k a. Ord k => k -> Map k a -> Map k a
Map.delete) Map key elt
m [key]
ks

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