Pathy.Path
- Package
- purescript-pathy
- Repository
- slamdata/purescript-pathy
#Path Source
data Path (a :: RelOrAbs) (b :: DirOrFile)
A type that describes a Path. All flavors of paths are described by this type, whether they are absolute or relative paths and whether they refer to files or directories.
- The type parameter
a
describes whether the path isRel
orAbs
. - The type parameter
b
describes whether the path isFile
orDir
.
To ensure type safety, there is no way for users to create a value of
this type directly. Instead, helpers should be used, such as rootDir
,
currentDir
, file
, dir
, (</>)
, and parsePath
.
This ADT allows invalid paths (e.g. paths inside files), but there is no possible way for such paths to be constructed by user-land code.
Instances
Eq (Path a b)
Ord (Path a b)
(IsRelOrAbs a, IsDirOrFile b) => Show (Path a b)
#currentDir Source
currentDir :: Path Rel Dir
The "current directory", which can be used to define relatively-located resources.
#in' Source
in' :: forall a. Name a -> Path Rel a
Creates a path which points to a relative directory or file of the specified name.
In most cases dir'
or file'
should be used instead,
but it's still there in case the segment type is going to be determined based
on some type variable.
p == maybe p (\(Tuple r n) -> r </> in' n) (peel p)
#extendPath Source
extendPath :: forall b a. Path a Dir -> Name b -> Path a b
Extends a path with a file or directory under the current path.
#appendPath Source
appendPath :: forall b a. IsRelOrAbs a => Path a Dir -> Path Rel b -> Path a b
Given a directory path, appends a relative path to extend the original path.
#parentAppend Source
parentAppend :: forall b a. IsRelOrAbs a => Path a Dir -> Path Rel b -> Path a b
Ascends into the parent of the specified directory, then descends into the specified path.
rootDir </> dir "foo" <..> dir "bar" = rootDir </> dir "bar"
#foldPath Source
foldPath :: forall r b a. r -> (Path Rel Dir -> r) -> (Path a Dir -> Name b -> r) -> Path a b -> r
A fold over Path
s. Since Path
has private constructors, this allows for
functions to be written over its constructors, similar to a total pattern
match.
- The first argument is the value to return for the
currentDir
/rootDir
at the base of the path. - The second argument is a function for handling a step into the parent
directory of the path it receives (eliminates
parentOf
). - The third argument is a function representing a file or directory within
the directory of the path it receives (eliminates
extendPath
).
#name Source
name :: forall b a. IsRelOrAbs a => IsDirOrFile b => Path a b -> Maybe (Name b)
Retrieves the name of the terminal segment in a path. Returns Nothing
if
the path is rootDir
/ currentDir
or some parentOf p
.
#renameTraverse Source
renameTraverse :: forall b a f. Applicative f => (Name b -> f (Name b)) -> Path a b -> f (Path a b)
Attempts to rename the terminal segment of a path using a function that
returns the result in some Applicative
. If the path is rootDir
/
currentDir
or a relative path that is ascending (../
) this will
have no effect.
#setExtension Source
setExtension :: forall b a. Path a b -> String -> Path a b
Sets the extension on the terminal segment of a path. If the path is
rootDir
/ currentDir
or a relative path that is ascending (../
) this
will have no effect.
file "image" <.> "png"
See splitName
and alterExtension
fore more examples.