Safe Haskell | None |
---|---|

Language | Haskell2010 |

Uses `relude`

as a default prelude.

# Documentation

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`

`>>>`

Just Red`parse "Red"`

`>>>`

Nothing`parse "Black"`