{-# OPTIONS_GHC -fno-warn-orphans #-}

module Data.Registry.Internal.MultiMap () where

import Data.MultiMap (MultiMap)
import Data.MultiMap qualified as MM
import Protolude as P hiding (show)
import Prelude (show)

instance (Show k, Show v) => Show (MultiMap k v) where
  show :: MultiMap k v -> String
show = forall a. Show a => a -> String
show forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall k a. MultiMap k a -> [(k, [a])]
MM.assocs

instance (Ord k) => Semigroup (MultiMap k v) where
  <> :: MultiMap k v -> MultiMap k v -> MultiMap k v
(<>) MultiMap k v
m1 MultiMap k v
m2 = forall k a. Ord k => [(k, a)] -> MultiMap k a
MM.fromList (forall k a. MultiMap k a -> [(k, a)]
MM.toList MultiMap k v
m1 forall a. Semigroup a => a -> a -> a
<> forall k a. MultiMap k a -> [(k, a)]
MM.toList MultiMap k v
m2)

instance (Ord k) => Monoid (MultiMap k v) where
  mempty :: MultiMap k v
mempty = forall k a. MultiMap k a
MM.empty
  mappend :: MultiMap k v -> MultiMap k v -> MultiMap k v
mappend = forall a. Semigroup a => a -> a -> a
(<>)