summoner- Tool for creating completely configured production Haskell projects.

Safe HaskellNone



Uses relude as a default prelude.



module Relude

inverseMap :: (Bounded a, Enum a, Ord k) => (a -> k) -> k -> Maybe a #

inverseMap f creates a function that is the inverse of a given function f. It does so by constructing Map for every value f a. The implementation makes sure that the Map is constructed only once and then shared for every call.

The complexity of reversed mapping though is \(\mathcal{O}(\log n)\).

Usually you want to use inverseMap to inverse show function.

>>> data Color = Red | Green | Blue deriving (Show, Enum, Bounded)
>>> parse = inverseMap show :: String -> Maybe Color
>>> parse "Red"
Just Red
>>> parse "Black"

universe :: (Bounded a, Enum a) => [a] #

Returns all values of some Bounded Enum in ascending order.

>>> data TrafficLight = Red | Blue | Green deriving (Show, Enum, Bounded)
>>> universe :: [TrafficLight]
>>> universe :: [Bool]