Skip to content

Commit 251db61

Browse files
committed
Add commonly used synonyms, pathName
1 parent d77b213 commit 251db61

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

src/Data/Path/Pathy.purs

+14-1
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ module Data.Path.Pathy
6868
import Data.Tuple(Tuple(..), fst, snd)
6969
import Data.Either(Either(..), either)
7070
import Data.Maybe(Maybe(..), maybe)
71+
import Data.Bifunctor(bimap)
7172

7273
-- | The (phantom) type of relative paths.
7374
foreign import data Rel :: *
@@ -95,7 +96,7 @@ module Data.Path.Pathy
9596
runFileName (FileName name) = name
9697

9798
-- | A newtype around a directory name.
98-
newtype DirName = DirName String
99+
newtype DirName = DirName String
99100

100101
-- | Unwraps the `DirName` newtype.
101102
runDirName :: DirName -> String
@@ -135,6 +136,15 @@ module Data.Path.Pathy
135136
-- | A type describing a directory whose location is absolutely specified.
136137
type AbsDir s = Path Abs Dir s
137138

139+
-- | A type describing a file or directory path.
140+
type AnyPath b s = Either (Path b Dir s) (Path b File s)
141+
142+
-- | A type describing a relative file or directory path.
143+
type RelPath s = AnyPath Rel s
144+
145+
-- | A type describing an absolute file or directory path.
146+
type AbsPath s = AnyPath Abs s
147+
138148
-- | Escapers encode segments or characters which have reserved meaning.
139149
newtype Escaper = Escaper (String -> String)
140150

@@ -199,6 +209,9 @@ module Data.Path.Pathy
199209
(DirIn _ d) -> Just d
200210
_ -> Nothing
201211

212+
pathName :: forall b s. AnyPath b s -> Either (Maybe DirName) FileName
213+
pathName = bimap dirName fileName
214+
202215
infixl 6 </>
203216

204217
-- | Given a directory path, appends either a file or directory to the path.

0 commit comments

Comments
 (0)