# Pastebin mWf23ECx class Failing f where warn :: String -> a -> f a err :: String -> f a newtype Coder f i o = Coder { runCoder :: i -> f o } deriving stock Functor deriving newtype (Semigroup, Monoid) deriving (Applicative, Monad) via (Star f i) fromKey :: (Failing f, Show k, Ixed m, Index m ~ k, IxValue m ~ v) => k -> Coder f v o -> Coder f m o fromKey k (Coder f) = Coder $ \m -> maybe (err $ "missing key: " <> show k) f $ m ^? ix k