git.iko.soy/typeable/http-api-data
on master help sign in
Streamlined `fromPathPiece` implementation.
54b0c62MomemtumMori
Web/PathPieces.hs+5−6
@@ -84,12 +84,11 @@ instance PathMultiPiece [L.Text] where
84 toPathMultiPiece = map $ S.concat . L.toChunks
84 toPathMultiPiece = map $ S.concat . L.toChunks
85
85
86instance (PathPiece a) => PathPiece (Maybe a) where
86instance (PathPiece a) => PathPiece (Maybe a) where
87− fromPathPiece s = if S.isPrefixOf "Just " s
87+ fromPathPiece s = case S.stripPrefix "Just " s of
88− then Just $ fromPathPiece $ fromJust $ S.stripPrefix "Just " s
88+ Just r -> Just $ fromPathPiece r
89− else
89+ _ -> case s of
90− if s == "Nothing"
91− then Just Nothing
90+ "Nothing" -> Just Nothing
92− else Nothing
91+ _ -> Nothing
93 toPathPiece m = case m of
92 toPathPiece m = case m of
94 Just s -> "Just " `S.append` toPathPiece s
93 Just s -> "Just " `S.append` toPathPiece s
95 _ -> "Nothing"
94 _ -> "Nothing"