git.iko.soy/typeable/http-api-data
on master help sign in
Rename parseBoundedCaseInsensitiveTextData
46b2df7Nickolay Kudasov
Web/HttpApiData.hs+1−1
@@ -17,7 +17,7 @@ module Web.HttpApiData (
17 -- * Helpers
17 -- * Helpers
18 showTextData,
18 showTextData,
19 readTextData,
19 readTextData,
20− parseBoundedCaseInsensitiveTextData,
20+ parseBoundedTextData,
21 parseUrlPieceWithPrefix,
21 parseUrlPieceWithPrefix,
22) where
22) where
23
23
Web/HttpApiData/Internal.hs+12−12
@@ -167,9 +167,9 @@ parseUrlPieceWithPrefix pattern input
167#if USE_TEXT_SHOW
167#if USE_TEXT_SHOW
168-- | Parse values case insensitively based on @'TextShow'@ instance.
168-- | Parse values case insensitively based on @'TextShow'@ instance.
169--
169--
170−-- >>> parseBoundedCaseInsensitiveTextData "true" :: Either Text Bool
170+-- >>> parseBoundedTextData "true" :: Either Text Bool
171-- Right True
171-- Right True
172−-- >>> parseBoundedCaseInsensitiveTextData "FALSE" :: Either Text Bool
172+-- >>> parseBoundedTextData "FALSE" :: Either Text Bool
173-- Right False
173-- Right False
174--
174--
175-- This can be used as a default implementation for enumeration types:
175-- This can be used as a default implementation for enumeration types:
@@ -181,26 +181,26 @@ parseUrlPieceWithPrefix pattern input
181-- showt = genericShowt
181-- showt = genericShowt
182--
182--
183-- instance FromHttpApiData MyData where
183-- instance FromHttpApiData MyData where
184−-- parseUrlPiece = parseBoundedCaseInsensitiveTextData
184+-- parseUrlPiece = parseBoundedTextData
185-- @
185-- @
186−parseBoundedCaseInsensitiveTextData :: forall a. (TextShow a, Bounded a, Enum a) => Text -> Either Text a
186+parseBoundedTextData :: forall a. (TextShow a, Bounded a, Enum a) => Text -> Either Text a
187#else
187#else
188-- | Parse values case insensitively based on @'Show'@ instance.
188-- | Parse values case insensitively based on @'Show'@ instance.
189--
189--
190−-- >>> parseBoundedCaseInsensitiveTextData "true" :: Either Text Bool
190+-- >>> parseBoundedTextData "true" :: Either Text Bool
191-- Right True
191-- Right True
192−-- >>> parseBoundedCaseInsensitiveTextData "FALSE" :: Either Text Bool
192+-- >>> parseBoundedTextData "FALSE" :: Either Text Bool
193-- Right False
193-- Right False
194--
194--
195-- This can be used as a default implementation for enumeration types:
195-- This can be used as a default implementation for enumeration types:
196--
196--
197-- >>> data MyData = Foo | Bar | Baz deriving (Show, Bounded, Enum)
197-- >>> data MyData = Foo | Bar | Baz deriving (Show, Bounded, Enum)
198−-- >>> instance FromHttpApiData MyData where parseUrlPiece = parseBoundedCaseInsensitiveTextData
198+-- >>> instance FromHttpApiData MyData where parseUrlPiece = parseBoundedTextData
199-- >>> parseUrlPiece "foo" :: Either Text MyData
199-- >>> parseUrlPiece "foo" :: Either Text MyData
200-- Right Foo
200-- Right Foo
201−parseBoundedCaseInsensitiveTextData :: forall a. (Show a, Bounded a, Enum a) => Text -> Either Text a
201+parseBoundedTextData :: forall a. (Show a, Bounded a, Enum a) => Text -> Either Text a
202#endif
202#endif
203−parseBoundedCaseInsensitiveTextData = parseMaybeTextData (flip lookup values . T.toLower)
203+parseBoundedTextData = parseMaybeTextData (flip lookup values . T.toLower)
204 where
204 where
205 values = map (showTextData &&& id) [minBound..maxBound :: a]
205 values = map (showTextData &&& id) [minBound..maxBound :: a]
206
206
@@ -221,7 +221,7 @@ readMaybeTextData = readMaybe . T.unpack
221-- >>> readTextData "true" :: Either Text Bool
221-- >>> readTextData "true" :: Either Text Bool
222-- Left "could not parse: `true'"
222-- Left "could not parse: `true'"
223--
223--
224−-- See @'parseBoundedCaseInsensitiveTextData'@.
224+-- See @'parseBoundedTextData'@.
225readTextData :: Read a => Text -> Either Text a
225readTextData :: Read a => Text -> Either Text a
226readTextData = parseMaybeTextData readMaybeTextData
226readTextData = parseMaybeTextData readMaybeTextData
227
227
@@ -346,8 +346,8 @@ instance FromHttpApiData Void where
346 parseUrlPiece _ = Left "Void cannot be parsed!"
346 parseUrlPiece _ = Left "Void cannot be parsed!"
347#endif
347#endif
348
348
349−instance FromHttpApiData Bool where parseUrlPiece = parseBoundedCaseInsensitiveTextData
349+instance FromHttpApiData Bool where parseUrlPiece = parseBoundedTextData
350−instance FromHttpApiData Ordering where parseUrlPiece = parseBoundedCaseInsensitiveTextData
350+instance FromHttpApiData Ordering where parseUrlPiece = parseBoundedTextData
351instance FromHttpApiData Double where parseUrlPiece = runReader rational
351instance FromHttpApiData Double where parseUrlPiece = runReader rational
352instance FromHttpApiData Float where parseUrlPiece = runReader rational
352instance FromHttpApiData Float where parseUrlPiece = runReader rational
353instance FromHttpApiData Int where parseUrlPiece = parseBounded (signed decimal)
353instance FromHttpApiData Int where parseUrlPiece = parseBounded (signed decimal)