@@ -38,10 +38,6 @@ import Text.ParserCombinators.ReadP (readP_to_S)
38import TextShow (TextShow, showt)
38import TextShow (TextShow, showt)
42−-- >>> :set -XDeriveGeneric
43−-- >>> import TextShow.Generic
45-- | Convert value to HTTP API data.
41-- | Convert value to HTTP API data.
46class ToHttpApiData a where
42class ToHttpApiData a where
47 {-# MINIMAL toUrlPiece | toQueryParam #-}
43 {-# MINIMAL toUrlPiece | toQueryParam #-}
@@ -113,10 +109,15 @@ parseMaybeTextData parse input =
114-- This can be used as a default implementation for enumeration types:
110-- This can be used as a default implementation for enumeration types:
116−-- >>> data MyData = Foo | Bar | Baz deriving (Show)
113+-- data MyData = Foo | Bar | Baz deriving (Generic)
115+-- instance TextShow MyData where
116+-- showt = genericShowt
117−-- >>> instance ToHttpApiData MyData where toUrlPiece = showTextData
118+-- instance ToHttpApiData MyData where
118−-- >>> toUrlPiece Foo
119+-- toUrlPiece = showTextData
120showTextData :: TextShow a => a -> Text
121showTextData :: TextShow a => a -> Text
121showTextData = T.toLower . showt
122showTextData = T.toLower . showt
@@ -166,11 +167,15 @@ parseUrlPieceWithPrefix pattern input
167-- This can be used as a default implementation for enumeration types:
168-- This can be used as a default implementation for enumeration types:
169−-- >>> data MyData = Foo | Bar | Baz deriving (Show, Bounded, Enum, Generic)
171+-- data MyData = Foo | Bar | Baz deriving (Show, Bounded, Enum, Generic)
170−-- >>> instance TextShow MyData where showt = genericShowt
173+-- instance TextShow MyData where
174+-- showt = genericShowt
176+-- instance FromHttpApiData MyData where
171−-- >>> instance FromHttpApiData MyData where parseUrlPiece = parseBoundedCaseInsensitiveTextData
177+-- parseUrlPiece = parseBoundedCaseInsensitiveTextData
172−-- >>> parseUrlPiece "foo" :: Either Text MyData
178+-- @
174parseBoundedCaseInsensitiveTextData :: forall a. (TextShow a, Bounded a, Enum a) => Text -> Either Text a
179parseBoundedCaseInsensitiveTextData :: forall a. (TextShow a, Bounded a, Enum a) => Text -> Either Text a
176-- | Parse values case insensitively based on @'Show'@ instance.
181-- | Parse values case insensitively based on @'Show'@ instance.