Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Added FilePath newtype to represent texts with slashes in them

  • Loading branch information...
commit 0cc9e65cba5ca4b6af05c1eb53ca27819a91de78 1 parent eacc4d4
Tom Lokhorst authored

Showing 1 changed file with 18 additions and 1 deletion. Show diff stats Hide diff stats

  1. +18 1 Web/Zwaluw.hs
19 Web/Zwaluw.hs
@@ -27,9 +27,12 @@ module Web.Zwaluw (
27 27 , rLeft, rRight, rEither
28 28 , rNothing, rJust, rMaybe
29 29 , rTrue, rFalse
  30 +
  31 + -- * FilePath data type and router
  32 + , FilePath, filePath
30 33 ) where
31 34
32   -import Prelude hiding ((.), id, (/))
  35 +import Prelude hiding ((.), id, (/), FilePath)
33 36 import Control.Monad (guard)
34 37 import Control.Category
35 38 import Data.Monoid
@@ -193,3 +196,17 @@ rMaybe r = rJust . r <> rNothing
193 196 $(deriveRouters ''Bool)
194 197 rTrue :: Router r (Bool :- r)
195 198 rFalse :: Router r (Bool :- r)
  199 +
  200 +-- | Represents a file path, including slashes
  201 +newtype FilePath = FilePath { unFilePath :: T.Text }
  202 +
  203 +instance Show FilePath where
  204 + showsPrec p (FilePath t) r = showsPrec p t r
  205 +
  206 +filePath :: Router r (FilePath :- r)
  207 +filePath = val parse' serialize
  208 + where
  209 + parse' "" = []
  210 + parse' s = [(FilePath . T.pack $ s, "")]
  211 + serialize = return . (++) . T.unpack . unFilePath
  212 +

0 comments on commit 0cc9e65

Please sign in to comment.
Something went wrong with that request. Please try again.