git.iko.soy/typeable/http-api-data
on master help sign in
Rename readEitherTextData and add a more detailed comment
bf75392Nickolay Kudasov
Web/HttpApiData.hs+1−1
@@ -16,7 +16,7 @@ module Web.HttpApiData (
16
16
17 -- * Helpers
17 -- * Helpers
18 showTextData,
18 showTextData,
19− readEitherTextData,
19+ readTextData,
20 parseBoundedCaseInsensitiveTextData,
20 parseBoundedCaseInsensitiveTextData,
21 parseUrlPieceWithPrefix,
21 parseUrlPieceWithPrefix,
22) where
22) where
Web/HttpApiData/Internal.hs+16−3
@@ -209,8 +209,21 @@ readMaybeTextData :: Read a => Text -> Maybe a
209readMaybeTextData = readMaybe . T.unpack
209readMaybeTextData = readMaybe . T.unpack
210
210
211-- | Parse URL piece using @'Read'@ instance.
211-- | Parse URL piece using @'Read'@ instance.
212+--
213+-- Use for types which do not involve letters:
214+--
215+-- >>> readTextData "1991-06-02" :: Either Text Day
216+-- Right 1991-06-02
217+--
218+-- This parser is case sensitive and will not match @'showTextData'@
219+-- in presense of letters:
220+--
221+-- >>> readTextData "true" :: Either Text Bool
222+-- Left "could not parse: `true'"
223+--
224+-- See @'parseBoundedCaseInsensitiveTextData'@.
212−readEitherTextData :: Read a => Text -> Either Text a
225+readTextData :: Read a => Text -> Either Text a
213−readEitherTextData = parseMaybeTextData readMaybeTextData
226+readTextData = parseMaybeTextData readMaybeTextData
214
227
215-- | Run @'Reader'@ as HTTP API data parser.
228-- | Run @'Reader'@ as HTTP API data parser.
216runReader :: Reader a -> Text -> Either Text a
229runReader :: Reader a -> Text -> Either Text a
@@ -355,7 +368,7 @@ instance FromHttpApiData L.Text where parseUrlPiece = Right . L.fromStrict
355-- |
368-- |
356-- >>> toGregorian <$> parseUrlPiece "2016-12-01"
369-- >>> toGregorian <$> parseUrlPiece "2016-12-01"
357-- Right (2016,12,1)
370-- Right (2016,12,1)
358−instance FromHttpApiData Day where parseUrlPiece = readEitherTextData
371+instance FromHttpApiData Day where parseUrlPiece = readTextData
359
372
360instance FromHttpApiData All where parseUrlPiece = fmap All . parseUrlPiece
373instance FromHttpApiData All where parseUrlPiece = fmap All . parseUrlPiece
361instance FromHttpApiData Any where parseUrlPiece = fmap Any . parseUrlPiece
374instance FromHttpApiData Any where parseUrlPiece = fmap Any . parseUrlPiece