-- Some extra functions to extend Data.Map

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

import GhcPrelude

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

insertList :: Ord key => [(key,elt)] -> Map key elt -> Map key elt
insertList :: [(key, elt)] -> Map key elt -> Map key elt
insertList xs :: [(key, elt)]
xs m :: Map key elt
m = (Map key elt -> (key, elt) -> Map key elt)
-> Map key elt -> [(key, elt)] -> Map key elt
forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
foldl' (\m :: Map key elt
m (k :: key
k, v :: elt
v) -> key -> elt -> Map key elt -> Map key elt
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 :: (elt -> elt -> elt) -> [(key, elt)] -> Map key elt -> Map key elt
insertListWith f :: elt -> elt -> elt
f xs :: [(key, elt)]
xs m0 :: Map key elt
m0 = (Map key elt -> (key, elt) -> Map key elt)
-> Map key elt -> [(key, elt)] -> Map key elt
forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
foldl' (\m :: Map key elt
m (k :: key
k, v :: elt
v) -> (elt -> elt -> elt) -> key -> elt -> Map key elt -> Map key elt
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 :: [key] -> Map key elt -> Map key elt
deleteList ks :: [key]
ks m :: Map key elt
m = (Map key elt -> key -> Map key elt)
-> Map key elt -> [key] -> Map key elt
forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
foldl' ((key -> Map key elt -> Map key elt)
-> Map key elt -> key -> Map key elt
forall a b c. (a -> b -> c) -> b -> a -> c
flip key -> Map key elt -> Map key elt
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 :: (elt -> a -> a) -> a -> Map key elt -> a
foldRight        = (elt -> a -> a) -> a -> Map key elt -> a
forall a b k. (a -> b -> b) -> b -> Map k a -> b
Map.foldr
foldRightWithKey :: (key -> elt -> a -> a) -> a -> Map key elt -> a
foldRightWithKey :: (key -> elt -> a -> a) -> a -> Map key elt -> a
foldRightWithKey = (key -> elt -> a -> a) -> a -> Map key elt -> a
forall k a b. (k -> a -> b -> b) -> b -> Map k a -> b
Map.foldrWithKey