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 = ([k] -> [k] -> [k]) -> [(v, [k])] -> Map v [k]
forall k a. Ord k => (a -> a -> a) -> [(k, a)] -> Map k a
fromListWith [k] -> [k] -> [k]
forall a. [a] -> [a] -> [a]
(++) [(v, [k])]
vks
  where
    kvs :: [(k, [v])]
kvs = Map k [v] -> [(k, [v])]
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]