git.iko.soy/typeable/http-api-data
on master help sign in
Add instances for Char
7dc6866Nickolay Kudasov
Web/HttpApiData.hs+8
@@ -124,6 +124,8 @@ parseBounded reader input = do
124instance ToHttpApiData () where
124instance ToHttpApiData () where
125 toUrlPiece () = "_"
125 toUrlPiece () = "_"
126
126
127+instance ToHttpApiData Char where toUrlPiece = T.singleton
128+
127instance ToHttpApiData Bool where toUrlPiece = showUrlPiece
129instance ToHttpApiData Bool where toUrlPiece = showUrlPiece
128instance ToHttpApiData Double where toUrlPiece = showUrlPiece
130instance ToHttpApiData Double where toUrlPiece = showUrlPiece
129instance ToHttpApiData Float where toUrlPiece = showUrlPiece
131instance ToHttpApiData Float where toUrlPiece = showUrlPiece
@@ -157,6 +159,12 @@ instance FromHttpApiData () where
157 parseUrlPiece "_" = return ()
159 parseUrlPiece "_" = return ()
158 parseUrlPiece s = defaultParseError s
160 parseUrlPiece s = defaultParseError s
159
161
162+instance FromHttpApiData Char where
163+ parseUrlPiece s =
164+ case T.uncons s of
165+ Just (c, s') | T.null s' -> return c
166+ _ -> defaultParseError s
167+
160instance FromHttpApiData Bool where parseUrlPiece = readEitherUrlPiece
168instance FromHttpApiData Bool where parseUrlPiece = readEitherUrlPiece
161instance FromHttpApiData Double where parseUrlPiece = runReader rational
169instance FromHttpApiData Double where parseUrlPiece = runReader rational
162instance FromHttpApiData Float where parseUrlPiece = runReader rational
170instance FromHttpApiData Float where parseUrlPiece = runReader rational
Web/PathPieces.hs+1
@@ -34,6 +34,7 @@ class PathPiece s where
34 toPathPiece = toUrlPiece
34 toPathPiece = toUrlPiece
35
35
36instance PathPiece ()
36instance PathPiece ()
37+instance PathPiece Char
37instance PathPiece Bool
38instance PathPiece Bool
38instance PathPiece Double
39instance PathPiece Double
39instance PathPiece Float
40instance PathPiece Float
test/main.hs+1
@@ -35,6 +35,7 @@ spec :: Spec
35spec = do
35spec = do
36 describe "PathPiece" $ do
36 describe "PathPiece" $ do
37 prop "toPathPiece <=> fromPathPiece ()" $ \(p :: ()) -> (toPathPiece <=> fromPathPiece) p
37 prop "toPathPiece <=> fromPathPiece ()" $ \(p :: ()) -> (toPathPiece <=> fromPathPiece) p
38+ prop "toPathPiece <=> fromPathPiece Char" $ \(p :: Char) -> (toPathPiece <=> fromPathPiece) p
38 prop "toPathPiece <=> fromPathPiece Bool" $ \(p :: Bool) -> (toPathPiece <=> fromPathPiece) p
39 prop "toPathPiece <=> fromPathPiece Bool" $ \(p :: Bool) -> (toPathPiece <=> fromPathPiece) p
39 prop "toPathPiece <=> fromPathPiece Int" $ \(p :: Int) -> (toPathPiece <=> fromPathPiece) p
40 prop "toPathPiece <=> fromPathPiece Int" $ \(p :: Int) -> (toPathPiece <=> fromPathPiece) p
40 prop "toPathPiece <=> fromPathPiece Int8" $ \(p :: Int8) -> (toPathPiece <=> fromPathPiece) p
41 prop "toPathPiece <=> fromPathPiece Int8" $ \(p :: Int8) -> (toPathPiece <=> fromPathPiece) p