Loading [MathJax]/jax/output/HTML-CSS/jax.js

summoner-1.1.0.1: Tool for creating completely configured production Haskell projects.

Safe HaskellNone
LanguageHaskell2010

Prelude

Description

Uses relude as a default prelude.

Synopsis

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 O(logn).

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"
Nothing

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]
[Red,Blue,Green]
>>> universe :: [Bool]
[False,True]