@@ -10,7 +10,6 @@ module Web.PathPieces
12import Data.Int (Int64)
12import Data.Int (Int64)
13−import Data.Maybe (fromJust)
14import qualified Data.Text as S
13import qualified Data.Text as S
15import qualified Data.Text.Lazy as L
14import qualified Data.Text.Lazy as L
16import qualified Data.Text.Read
15import qualified Data.Text.Read
@@ -67,6 +66,16 @@ instance PathPiece Day where
67 _ -> Nothing
66 _ -> Nothing
68 toPathPiece = S.pack . show
67 toPathPiece = S.pack . show
69+instance (PathPiece a) => PathPiece (Maybe a) where
70+ fromPathPiece s = case S.stripPrefix "Just " s of
71+ Just r -> Just `fmap` fromPathPiece r
73+ "Nothing" -> Just Nothing
75+ toPathPiece m = case m of
76+ Just s -> "Just " `S.append` toPathPiece s
70class PathMultiPiece s where
79class PathMultiPiece s where
71 fromPathMultiPiece :: [S.Text] -> Maybe s
80 fromPathMultiPiece :: [S.Text] -> Maybe s
72 toPathMultiPiece :: s -> [S.Text]
81 toPathMultiPiece :: s -> [S.Text]
@@ -83,16 +92,6 @@ instance PathMultiPiece [L.Text] where
83 fromPathMultiPiece = Just . map (L.fromChunks . return)
92 fromPathMultiPiece = Just . map (L.fromChunks . return)
84 toPathMultiPiece = map $ S.concat . L.toChunks
93 toPathMultiPiece = map $ S.concat . L.toChunks
86−instance (PathPiece a) => PathPiece (Maybe a) where
87− fromPathPiece s = case S.stripPrefix "Just " s of
88− Just r -> Just $ fromPathPiece r
90− "Nothing" -> Just Nothing
92− toPathPiece m = case m of
93− Just s -> "Just " `S.append` toPathPiece s
96{-# DEPRECATED toSinglePiece "Use toPathPiece instead of toSinglePiece" #-}
95{-# DEPRECATED toSinglePiece "Use toPathPiece instead of toSinglePiece" #-}
97toSinglePiece :: PathPiece p => p -> S.Text
96toSinglePiece :: PathPiece p => p -> S.Text
98toSinglePiece = toPathPiece
97toSinglePiece = toPathPiece