enum-text 0.5.0.0 → 0.5.1.0
raw patch · 4 files changed
+50/−3 lines, 4 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
+ Text.Enum.Text: UsingEnumText :: a -> UsingEnumText a
+ Text.Enum.Text: [_UsingEnumText] :: UsingEnumText a -> a
+ Text.Enum.Text: instance Text.Enum.Text.EnumText a => Formatting.Buildable.Buildable (Text.Enum.Text.UsingEnumText a)
+ Text.Enum.Text: instance Text.Enum.Text.EnumText a => Text.Enum.Text.TextParsable (Text.Enum.Text.UsingEnumText a)
+ Text.Enum.Text: newtype UsingEnumText a
Files
- ChangeLog.md +5/−0
- README.md +17/−1
- enum-text.cabal +2/−2
- src/Text/Enum/Text.hs +26/−0
ChangeLog.md view
@@ -1,3 +1,8 @@+# 0.5.1.0++ * add @UsingEnumText@ wrapper type and instances for+ deriving @Buildable@ and @TextParsable@ instances+ # 0.5.0.0 * add basic TextParsable instances and toolkit functions
README.md view
@@ -5,7 +5,7 @@ back again into Text with the provided `TextParsable` type class. To get the `Buildable` and `TextParsable` instances for an enumerated data type-use the following pattern:+the following pattern can be used without any language extensions: ``` import Fmt@@ -17,6 +17,22 @@ instance EnumText Foo instance Buildable Foo where build = buildEnumText instance TextParsable Foo where parseText = parseEnumText+```++With the `DeriveAnyClass` language extension you can list `EnumText` in the+`deriving` clause, and with `DerivingVia` (available from GHC 8.6.1) you can+derive `via` `UsingEnumText` as follows:++```+{-# LANGUAGE DeriveAnyClass #-}+{-# LANGUAGE DerivingVia #-}++import Fmt+import Text.Enum.Text++data Foo = FOO_bar | FOO_bar_baz+ deriving (Bounded,Enum,EnumText,Eq,Ord,Show)+ deriving (Buildable,TextParsable) via UsingEnumText Foo ``` This will use the default configuration for generating the text of each
enum-text.cabal view
@@ -4,10 +4,10 @@ -- -- see: https://github.com/sol/hpack ----- hash: 0aa3dafda03153aaeb2d912503d7c418a6e7beaba9d3a0830cf570112e6f8500+-- hash: aa4522c3c0e28379109cad28a0f168141981649e20d845d6327e43f08f4c8024 name: enum-text-version: 0.5.0.0+version: 0.5.1.0 synopsis: A text rendering and parsing toolkit for enumerated types description: A text rendering and parsing toolkit for enumerated types. Please see the README on GitHub at <https://github.com/cdornan/enum-text#readme> category: Text
src/Text/Enum/Text.hs view
@@ -6,6 +6,7 @@ module Text.Enum.Text ( EnumText(..)+ , UsingEnumText(..) , TextParsable(..) , EnumTextConfig(..) , defaultEnumTextConfig@@ -39,6 +40,23 @@ instance TextParsable Foo where parseText = parseEnumText @ +With the @DeriveAnyClass@ language extension you can list @EnumText@ in the+@deriving@ clause, and with @DerivingVia@ (available from GHC 8.6.1) you can+derive @via@ @UsingEnumText@ as follows:+++@+{\-\# LANGUAGE DeriveAnyClass #-\}+{\-\# LANGUAGE DerivingVia #-\}++import Fmt+import Text.Enum.Text++data Foo = FOO_bar | FOO_bar_baz+ deriving (Bounded,Enum,EnumText,Eq,Ord,Show)+ deriving (Buildable,TextParsable) via UsingEnumText Foo+@+ -} class ( Buildable e , Bounded e@@ -81,6 +99,14 @@ -- | For hashing @e@ with the 'renderEnumText' representation. hashWithSaltEnumText :: Int -> e -> Int hashWithSaltEnumText n = hashWithSalt n . toFieldEnumText++newtype UsingEnumText a = UsingEnumText { _UsingEnumText :: a }++instance EnumText a => Buildable (UsingEnumText a) where+ build (UsingEnumText x) = buildEnumText x++instance EnumText a => TextParsable (UsingEnumText a) where+ parseText x = UsingEnumText <$> parseEnumText x -------------------------------------------------------------------------------