git.iko.soy/typeable/http-api-data
on master help sign in
Add instances for Void
f5bc108Nickolay Kudasov
Web/HttpApiData.hs+15
@@ -1,3 +1,4 @@
1+{-# LANGUAGE CPP #-}
1{-# LANGUAGE DefaultSignatures #-}
2{-# LANGUAGE DefaultSignatures #-}
2{-# LANGUAGE FlexibleInstances #-}
3{-# LANGUAGE FlexibleInstances #-}
3{-# LANGUAGE OverloadedStrings #-}
4{-# LANGUAGE OverloadedStrings #-}
@@ -38,6 +39,10 @@ import qualified Data.Text.Lazy as L
38import Data.Time (Day)
39import Data.Time (Day)
39import Data.Version
40import Data.Version
40
41
42+#if MIN_VERSION_base(4,8,0)
43+import Data.Void
44+#endif
45+
41import Text.Read (readMaybe)
46import Text.Read (readMaybe)
42import Text.ParserCombinators.ReadP (readP_to_S)
47import Text.ParserCombinators.ReadP (readP_to_S)
43
48
@@ -134,6 +139,11 @@ instance ToHttpApiData Char where toUrlPiece = T.singleton
134instance ToHttpApiData Version where
139instance ToHttpApiData Version where
135 toUrlPiece = T.pack . showVersion
140 toUrlPiece = T.pack . showVersion
136
141
142+#if MIN_VERSION_base(4,8,0)
143+instance ToHttpApiData Void where
144+ toUrlPiece = absurd
145+#endif
146+
137instance ToHttpApiData Bool where toUrlPiece = showUrlPiece
147instance ToHttpApiData Bool where toUrlPiece = showUrlPiece
138instance ToHttpApiData Double where toUrlPiece = showUrlPiece
148instance ToHttpApiData Double where toUrlPiece = showUrlPiece
139instance ToHttpApiData Float where toUrlPiece = showUrlPiece
149instance ToHttpApiData Float where toUrlPiece = showUrlPiece
@@ -201,6 +211,11 @@ instance FromHttpApiData Text where parseUrlPiece = Right
201instance FromHttpApiData L.Text where parseUrlPiece = Right . L.fromStrict
211instance FromHttpApiData L.Text where parseUrlPiece = Right . L.fromStrict
202instance FromHttpApiData Day where parseUrlPiece = readEitherUrlPiece
212instance FromHttpApiData Day where parseUrlPiece = readEitherUrlPiece
203
213
214+#if MIN_VERSION_base(4,8,0)
215+instance FromHttpApiData Void where
216+ parseUrlPiece _ = Left "Void cannot be parsed!"
217+#endif
218+
204-- |
219-- |
205-- >>> parseUrlPiece "Just 123" :: Either Text (Maybe Int)
220-- >>> parseUrlPiece "Just 123" :: Either Text (Maybe Int)
206-- Right (Just 123)
221-- Right (Just 123)
Web/PathPieces.hs+9
@@ -1,3 +1,4 @@
1+{-# LANGUAGE CPP #-}
1{-# LANGUAGE DefaultSignatures #-}
2{-# LANGUAGE DefaultSignatures #-}
2{-# LANGUAGE FlexibleInstances #-}
3{-# LANGUAGE FlexibleInstances #-}
3{-# LANGUAGE OverloadedStrings #-}
4{-# LANGUAGE OverloadedStrings #-}
@@ -20,6 +21,10 @@ import Data.Version (Version)
20import Data.Time (Day)
21import Data.Time (Day)
21import Text.Read (readMaybe)
22import Text.Read (readMaybe)
22
23
24+#if MIN_VERSION_base(4,8,0)
25+import Data.Void (Void)
26+#endif
27+
23import Web.HttpApiData
28import Web.HttpApiData
24
29
25-- | Convert Haskell values to and from route piece.
30-- | Convert Haskell values to and from route piece.
@@ -55,6 +60,10 @@ instance PathPiece L.Text
55instance PathPiece Day
60instance PathPiece Day
56instance PathPiece Version
61instance PathPiece Version
57
62
63+#if MIN_VERSION_base(4,8,0)
64+instance PathPiece Void
65+#endif
66+
58-- | Wrapped @'PathPiece'@ value.
67-- | Wrapped @'PathPiece'@ value.
59newtype WrappedPathPiece a = WrappedPathPiece { unwrapPathPiece :: a }
68newtype WrappedPathPiece a = WrappedPathPiece { unwrapPathPiece :: a }
60
69