packages feed

relude 0.1.0 → 0.1.1

raw patch · 4 files changed

+31/−3 lines, 4 filessetup-changed

Files

CHANGELOG.md view
@@ -1,6 +1,12 @@ Change log ========== +0.1.1+=====++* [#44](https://github.com/kowainik/relude/issues/44)+  Implement parser deriviation from pretty-printers+ 0.1.0 ===== 
− Setup.hs
@@ -1,2 +0,0 @@-import Distribution.Simple-main = defaultMain
relude.cabal view
@@ -1,5 +1,5 @@ name:                relude-version:             0.1.0+version:             0.1.1 synopsis:            Custom prelude from Kowainik description:     == Goals
src/Relude/Extra/Enum.hs view
@@ -3,12 +3,15 @@  module Relude.Extra.Enum        ( universe+       , inverseMap        , next        , safeToEnum        ) where  import Relude +import qualified Data.Map.Strict as M+ -- $setup -- >>> :set -XTypeApplications @@ -22,6 +25,27 @@ -} universe :: (Bounded a, Enum a) => [a] universe = [minBound .. maxBound]++{- | Creates a function that is the inverse of a given function @f@.++>>> data Color = Red | Green | Blue deriving (Show, Enum, Bounded)+>>> parse = inverseMap show :: String -> Maybe Color+>>> parse "Red"+Just Red+>>> parse "Black"+Nothing+-}+inverseMap :: forall a k. (Bounded a, Enum a, Ord k)+           => (a -> k)+           -> k+           -> Maybe a+inverseMap f = \x -> M.lookup x dict+    where+        dict :: M.Map k a+        dict = M.fromList $ zip (map f univ) univ++        univ :: [a]+        univ = universe  {- | Like 'succ', but doesn't fail on 'maxBound'. Instead it returns 'minBound'.