@@ -38,10 +38,6 @@ import Text.ParserCombinators.ReadP (readP_to_S)
3838import TextShow (TextShow, showt)
3939#endif
4040
41−-- $setup
42−-- >>> :set -XDeriveGeneric
43−-- >>> import TextShow.Generic
44−
4541-- | Convert value to HTTP API data.
4642class ToHttpApiData a where
4743 {-# MINIMAL toUrlPiece | toQueryParam #-}
@@ -113,10 +109,15 @@ parseMaybeTextData parse input =
113109--
114110-- This can be used as a default implementation for enumeration types:
115111--
116−-- >>> data MyData = Foo | Bar | Baz deriving (Show)
117−-- >>> instance ToHttpApiData MyData where toUrlPiece = showTextData
118−-- >>> toUrlPiece Foo
119−-- "foo"
112+-- @
113+-- data MyData = Foo | Bar | Baz deriving (Generic)
114+--
115+-- instance TextShow MyData where
116+-- showt = genericShowt
117+--
118+-- instance ToHttpApiData MyData where
119+-- toUrlPiece = showTextData
120+-- @
120121showTextData :: TextShow a => a -> Text
121122showTextData = T.toLower . showt
122123#else
@@ -166,11 +167,15 @@ parseUrlPieceWithPrefix pattern input
166167--
167168-- This can be used as a default implementation for enumeration types:
168169--
169−-- >>> data MyData = Foo | Bar | Baz deriving (Show, Bounded, Enum, Generic)
170−-- >>> instance TextShow MyData where showt = genericShowt
171−-- >>> instance FromHttpApiData MyData where parseUrlPiece = parseBoundedCaseInsensitiveTextData
172−-- >>> parseUrlPiece "foo" :: Either Text MyData
173−-- Right Foo
170+-- @
171+-- data MyData = Foo | Bar | Baz deriving (Show, Bounded, Enum, Generic)
172+--
173+-- instance TextShow MyData where
174+-- showt = genericShowt
175+--
176+-- instance FromHttpApiData MyData where
177+-- parseUrlPiece = parseBoundedCaseInsensitiveTextData
178+-- @
174179parseBoundedCaseInsensitiveTextData :: forall a. (TextShow a, Bounded a, Enum a) => Text -> Either Text a
175180#else
176181-- | Parse values case insensitively based on @'Show'@ instance.