{-# LANGUAGE ScopedTypeVariables #-}
module Language.Github.Actions.Internal (inverseMap) where
import qualified Data.Map as Map
inverseMap ::
forall a k.
(Bounded a, Enum a, Ord k) =>
(a -> k) ->
(k -> Maybe a)
inverseMap :: forall a k. (Bounded a, Enum a, Ord k) => (a -> k) -> k -> Maybe a
inverseMap a -> k
f = (k -> Map k a -> Maybe a
forall k a. Ord k => k -> Map k a -> Maybe a
`Map.lookup` Map k a
dict)
where
dict :: Map.Map k a
dict :: Map k a
dict = [(k, a)] -> Map k a
forall k a. Ord k => [(k, a)] -> Map k a
Map.fromList ((\a
a -> (a -> k
f a
a, a
a)) (a -> (k, a)) -> [a] -> [(k, a)]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [a
forall a. Bounded a => a
minBound .. a
forall a. Bounded a => a
maxBound])