git.iko.soy/typeable/http-api-data
on master help sign in
Add instances for Char
commit7dc68669416701ad6ae50d3ac4c3cc681a457dea authorNickolay Kudasov <nickolay.kudasov@gmail.com> dateMon 5 Oct 2015, 23:55 (11 years ago) parent9b260fb
3 files changed+10
Web/HttpApiData.hs+8 Web/PathPieces.hs+1 test/main.hs+1
Web/HttpApiData.hs+8
@@ -124,6 +124,8 @@ parseBounded reader input = do
124124instance ToHttpApiData () where
125125 toUrlPiece () = "_"
126126
127+instance ToHttpApiData Char where toUrlPiece = T.singleton
128+
127129instance ToHttpApiData Bool where toUrlPiece = showUrlPiece
128130instance ToHttpApiData Double where toUrlPiece = showUrlPiece
129131instance ToHttpApiData Float where toUrlPiece = showUrlPiece
@@ -157,6 +159,12 @@ instance FromHttpApiData () where
157159 parseUrlPiece "_" = return ()
158160 parseUrlPiece s = defaultParseError s
159161
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+
160168instance FromHttpApiData Bool where parseUrlPiece = readEitherUrlPiece
161169instance FromHttpApiData Double where parseUrlPiece = runReader rational
162170instance FromHttpApiData Float where parseUrlPiece = runReader rational
Web/PathPieces.hs+1
@@ -34,6 +34,7 @@ class PathPiece s where
3434 toPathPiece = toUrlPiece
3535
3636instance PathPiece ()
37+instance PathPiece Char
3738instance PathPiece Bool
3839instance PathPiece Double
3940instance PathPiece Float
test/main.hs+1
@@ -35,6 +35,7 @@ spec :: Spec
3535spec = do
3636 describe "PathPiece" $ do
3737 prop "toPathPiece <=> fromPathPiece ()" $ \(p :: ()) -> (toPathPiece <=> fromPathPiece) p
38+ prop "toPathPiece <=> fromPathPiece Char" $ \(p :: Char) -> (toPathPiece <=> fromPathPiece) p
3839 prop "toPathPiece <=> fromPathPiece Bool" $ \(p :: Bool) -> (toPathPiece <=> fromPathPiece) p
3940 prop "toPathPiece <=> fromPathPiece Int" $ \(p :: Int) -> (toPathPiece <=> fromPathPiece) p
4041 prop "toPathPiece <=> fromPathPiece Int8" $ \(p :: Int8) -> (toPathPiece <=> fromPathPiece) p