git.iko.soy/typeable/http-api-data
on master help sign in
Add documentation for PathPiece/PathMultiPiece classes
f0a5c50Nickolay Kudasov
Web/PathPieces.hs+8−2
@@ -15,11 +15,14 @@ import Text.Read (readMaybe)
15
15
16import Web.HttpApiData
16import Web.HttpApiData
17
17
18+-- | Convert Haskell values to and from route pieces.
18class PathPiece s where
19class PathPiece s where
20+ -- | Convert from route piece.
19 fromPathPiece :: S.Text -> Maybe s
21 fromPathPiece :: S.Text -> Maybe s
20 default fromPathPiece :: FromHttpApiData s => S.Text -> Maybe s
22 default fromPathPiece :: FromHttpApiData s => S.Text -> Maybe s
21 fromPathPiece = either (const Nothing) Just . parseUrlPiece
23 fromPathPiece = either (const Nothing) Just . parseUrlPiece
22
24
25+ -- | Convert to route piece.
23 toPathPiece :: s -> S.Text
26 toPathPiece :: s -> S.Text
24 default toPathPiece :: ToHttpApiData s => s -> S.Text
27 default toPathPiece :: ToHttpApiData s => s -> S.Text
25 toPathPiece = toUrlPiece
28 toPathPiece = toUrlPiece
@@ -56,9 +59,12 @@ instance (PathPiece a) => PathPiece (Maybe a) where
56 Just s -> "Just " `S.append` toPathPiece s
59 Just s -> "Just " `S.append` toPathPiece s
57 _ -> "Nothing"
60 _ -> "Nothing"
58
61
62+-- | Convert Haskell values to and from sequence of route pieces.
59class PathMultiPiece s where
63class PathMultiPiece s where
64+ -- | Convert from sequence of route pieces.
60− fromPathMultiPiece :: [S.Text] -> Maybe s
65+ fromPathMultiPiece :: [S.Text] -> Maybe s
66+ -- | Convert to sequence of route pieces.
61− toPathMultiPiece :: s -> [S.Text]
67+ toPathMultiPiece :: s -> [S.Text]
62
68
63instance PathPiece a => PathMultiPiece [a] where
69instance PathPiece a => PathMultiPiece [a] where
64 fromPathMultiPiece = mapM fromPathPiece
70 fromPathMultiPiece = mapM fromPathPiece