git.iko.soy/typeable/http-api-data
on master help sign in
Add default signature for PathPiece to use To/FromHttpApiData
commitf440e7ab9e73aac61071d75e6c1a330ea51c4a1a authorNickolay Kudasov <nickolay.kudasov@gmail.com> dateSun 4 Oct 2015, 01:44 (11 years ago) parent4610703
1 file changed+10−3
Web/PathPieces.hs+10−3
Web/PathPieces.hs+10−3
@@ -1,4 +1,4 @@
1−{-# LANGUAGE FlexibleInstances, TypeSynonymInstances, OverloadedStrings #-}
1+{-# LANGUAGE FlexibleInstances, TypeSynonymInstances, OverloadedStrings, DefaultSignatures #-}
22module Web.PathPieces
33 ( PathPiece (..)
44 , PathMultiPiece (..)
@@ -15,9 +15,16 @@ import Data.Time (Day)
1515import Control.Exception (assert)
1616import Text.Read (readMaybe)
1717
18+import Web.HttpApiData
19+
1820class PathPiece s where
19− fromPathPiece :: S.Text -> Maybe s
20− toPathPiece :: s -> S.Text
21+ fromPathPiece :: S.Text -> Maybe s
22+ default fromPathPiece :: FromHttpApiData s => S.Text -> Maybe s
23+ fromPathPiece = either (const Nothing) Just . parseUrlPiece
24+
25+ toPathPiece :: s -> S.Text
26+ default toPathPiece :: ToHttpApiData s => s -> S.Text
27+ toPathPiece = toUrlPiece
2128
2229instance PathPiece () where
2330 fromPathPiece t = if t == "_" then Just () else Nothing