From 251db6126f677ad27ec12eb0d3f0d0f4f9ea1561 Mon Sep 17 00:00:00 2001 From: Gary Burgess Date: Thu, 21 Apr 2016 19:08:23 +0100 Subject: [PATCH] Add commonly used synonyms, pathName --- src/Data/Path/Pathy.purs | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/Data/Path/Pathy.purs b/src/Data/Path/Pathy.purs index ad8c34f..1f11e0b 100644 --- a/src/Data/Path/Pathy.purs +++ b/src/Data/Path/Pathy.purs @@ -68,6 +68,7 @@ module Data.Path.Pathy import Data.Tuple(Tuple(..), fst, snd) import Data.Either(Either(..), either) import Data.Maybe(Maybe(..), maybe) + import Data.Bifunctor(bimap) -- | The (phantom) type of relative paths. foreign import data Rel :: * @@ -95,7 +96,7 @@ module Data.Path.Pathy runFileName (FileName name) = name -- | A newtype around a directory name. - newtype DirName = DirName String + newtype DirName = DirName String -- | Unwraps the `DirName` newtype. runDirName :: DirName -> String @@ -135,6 +136,15 @@ module Data.Path.Pathy -- | A type describing a directory whose location is absolutely specified. type AbsDir s = Path Abs Dir s + -- | A type describing a file or directory path. + type AnyPath b s = Either (Path b Dir s) (Path b File s) + + -- | A type describing a relative file or directory path. + type RelPath s = AnyPath Rel s + + -- | A type describing an absolute file or directory path. + type AbsPath s = AnyPath Abs s + -- | Escapers encode segments or characters which have reserved meaning. newtype Escaper = Escaper (String -> String) @@ -199,6 +209,9 @@ module Data.Path.Pathy (DirIn _ d) -> Just d _ -> Nothing + pathName :: forall b s. AnyPath b s -> Either (Maybe DirName) FileName + pathName = bimap dirName fileName + infixl 6 -- | Given a directory path, appends either a file or directory to the path.