git.iko.soy/typeable/http-api-data
on master help sign in
Replace doctests for TextShow with plain code blocks (haddock does not support CPP)
017e397Nickolay Kudasov
Web/HttpApiData/Internal.hs+18−13
@@ -38,10 +38,6 @@ import Text.ParserCombinators.ReadP (readP_to_S)
38import TextShow (TextShow, showt)
38import TextShow (TextShow, showt)
39#endif
39#endif
40
40
41−-- $setup
42−-- >>> :set -XDeriveGeneric
43−-- >>> import TextShow.Generic
44−
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 =
113--
109--
114-- This can be used as a default implementation for enumeration types:
110-- This can be used as a default implementation for enumeration types:
115--
111--
112+-- @
116−-- >>> data MyData = Foo | Bar | Baz deriving (Show)
113+-- data MyData = Foo | Bar | Baz deriving (Generic)
114+--
115+-- instance TextShow MyData where
116+-- showt = genericShowt
117+--
117−-- >>> instance ToHttpApiData MyData where toUrlPiece = showTextData
118+-- instance ToHttpApiData MyData where
118−-- >>> toUrlPiece Foo
119+-- toUrlPiece = showTextData
119−-- "foo"
120+-- @
120showTextData :: TextShow a => a -> Text
121showTextData :: TextShow a => a -> Text
121showTextData = T.toLower . showt
122showTextData = T.toLower . showt
122#else
123#else
@@ -166,11 +167,15 @@ parseUrlPieceWithPrefix pattern input
166--
167--
167-- This can be used as a default implementation for enumeration types:
168-- This can be used as a default implementation for enumeration types:
168--
169--
170+-- @
169−-- >>> data MyData = Foo | Bar | Baz deriving (Show, Bounded, Enum, Generic)
171+-- data MyData = Foo | Bar | Baz deriving (Show, Bounded, Enum, Generic)
172+--
170−-- >>> instance TextShow MyData where showt = genericShowt
173+-- instance TextShow MyData where
174+-- showt = genericShowt
175+--
176+-- instance FromHttpApiData MyData where
171−-- >>> instance FromHttpApiData MyData where parseUrlPiece = parseBoundedCaseInsensitiveTextData
177+-- parseUrlPiece = parseBoundedCaseInsensitiveTextData
172−-- >>> parseUrlPiece "foo" :: Either Text MyData
178+-- @
173−-- Right Foo
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
175#else
180#else
176-- | Parse values case insensitively based on @'Show'@ instance.
181-- | Parse values case insensitively based on @'Show'@ instance.