aboutsummaryrefslogtreecommitdiff
path: root/src/Text/Pandoc/Readers/Odt/Generic/SetMap.hs
blob: 12d65695d8b45626cc37fc2aefacdfaa7e78b288 (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
30
31
32
{-# LANGUAGE NoImplicitPrelude #-}
{- |
   Module      : Text.Pandoc.Readers.Odt.Generic.SetMap
   Copyright   : Copyright (C) 2015 Martin Linnemann
   License     : GNU GPL, version 2 or above

   Maintainer  : Martin Linnemann <theCodingMarlin@googlemail.com>
   Stability   : alpha
   Portability : portable

A map of values to sets of values.
-}

module Text.Pandoc.Readers.Odt.Generic.SetMap where

import Prelude
import qualified Data.Map as M
import qualified Data.Set as S

type SetMap k v = M.Map k (S.Set v)

empty :: SetMap k v
empty = M.empty

fromList :: (Ord k, Ord v) => [(k,v)] -> SetMap k v
fromList = foldr (uncurry insert) empty

insert :: (Ord k, Ord v) => k -> v -> SetMap k v -> SetMap k v
insert key value setMap = M.insertWith S.union key (S.singleton value) setMap

union3 :: (Ord k) => SetMap k v -> SetMap k v -> SetMap k v -> SetMap k v
union3 sm1 sm2 sm3 = sm1 `M.union` sm2 `M.union` sm3