Skip to content

Commit

Permalink
Merge pull request #15 from garyb/either-additions
Browse files Browse the repository at this point in the history
Add commonly used synonyms, pathName
  • Loading branch information
garyb committed Apr 21, 2016
2 parents d77b213 + 251db61 commit 7b2e5b2
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/Data/Path/Pathy.purs
Original file line number Diff line number Diff line change
Expand Up @@ -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 :: *
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit 7b2e5b2

Please sign in to comment.