hasPrefix
lib.path.hasPrefix
Docs pulled from | This Revision | about 3 hours ago
Whether the first path is a component-wise prefix of the second path.
Laws:
-
hasPrefix p q
is only true ifq == append p s
for some subpaths
. -
hasPrefix
is a non-strict partial order over the set of all path values.
Inputs
path1
-
1. Function argument
Type
hasPrefix :: Path -> Path -> Bool
Examples
hasPrefix
usage example
hasPrefix /foo /foo/bar
=> true
hasPrefix /foo /foo
=> true
hasPrefix /foo/bar /foo
=> false
hasPrefix /. /foo
=> true
Noogle detected
Implementation
The following is the current implementation of this function.
hasPrefix =
path1:
assert assertMsg (isPath path1)
"lib.path.hasPrefix: First argument is of type ${typeOf path1}, but a path was expected";
let
path1Deconstructed = deconstructPath path1;
in
path2:
assert assertMsg (isPath path2)
"lib.path.hasPrefix: Second argument is of type ${typeOf path2}, but a path was expected";
let
path2Deconstructed = deconstructPath path2;
in
assert assertMsg (path1Deconstructed.root == path2Deconstructed.root) ''
lib.path.hasPrefix: Filesystem roots must be the same for both paths, but paths with different roots were given:
first argument: "${toString path1}" with root "${toString path1Deconstructed.root}"
second argument: "${toString path2}" with root "${toString path2Deconstructed.root}"'';
take (length path1Deconstructed.components) path2Deconstructed.components
== path1Deconstructed.components;