git.iko.soy/typeable/http-api-data
on master help sign in
Rename readEitherTextData and add a more detailed comment
commitbf75392f4a771f3bc4b03cd10f0073f4fbc255b6 authorNickolay Kudasov <nickolay.kudasov@gmail.com> dateSat 10 Oct 2015, 23:55 (11 years ago) parentda22ac5
2 files changed+17−4
Web/HttpApiData.hs+1−1 Web/HttpApiData/Internal.hs+16−3
Web/HttpApiData.hs+1−1
@@ -16,7 +16,7 @@ module Web.HttpApiData (
1616
1717 -- * Helpers
1818 showTextData,
19− readEitherTextData,
19+ readTextData,
2020 parseBoundedCaseInsensitiveTextData,
2121 parseUrlPieceWithPrefix,
2222) where
Web/HttpApiData/Internal.hs+16−3
@@ -209,8 +209,21 @@ readMaybeTextData :: Read a => Text -> Maybe a
209209readMaybeTextData = readMaybe . T.unpack
210210
211211-- | Parse URL piece using @'Read'@ instance.
212−readEitherTextData :: Read a => Text -> Either Text a
213−readEitherTextData = parseMaybeTextData readMaybeTextData
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'@.
225+readTextData :: Read a => Text -> Either Text a
226+readTextData = parseMaybeTextData readMaybeTextData
214227
215228-- | Run @'Reader'@ as HTTP API data parser.
216229runReader :: Reader a -> Text -> Either Text a
@@ -355,7 +368,7 @@ instance FromHttpApiData L.Text where parseUrlPiece = Right . L.fromStrict
355368-- |
356369-- >>> toGregorian <$> parseUrlPiece "2016-12-01"
357370-- Right (2016,12,1)
358−instance FromHttpApiData Day where parseUrlPiece = readEitherTextData
371+instance FromHttpApiData Day where parseUrlPiece = readTextData
359372
360373instance FromHttpApiData All where parseUrlPiece = fmap All . parseUrlPiece
361374instance FromHttpApiData Any where parseUrlPiece = fmap Any . parseUrlPiece