module Utils.Drasil.Maps where

import Data.Map.Strict

invert :: Ord v => Map k [v] -> Map v [k]
invert :: forall v k. Ord v => Map k [v] -> Map v [k]
invert Map k [v]
m = forall k a. Ord k => (a -> a -> a) -> [(k, a)] -> Map k a
fromListWith forall a. [a] -> [a] -> [a]
(++) [(v, [k])]
vks
  where
    kvs :: [(k, [v])]
kvs = forall k a. Map k a -> [(k, a)]
toList Map k [v]
m
    vks :: [(v, [k])]
vks = [(v
v, [k
k]) | (k
k, [v]
vs) <- [(k, [v])]
kvs, v
v <- [v]
vs]