parent method
Returns the Path without its final component, if there is one. This means it returns Some("") for relative paths with one component. Returns None if the path terminates in a root or prefix, or if it’s the empty string.
Implementation
Option<Path> parent() {
final comps = components().toList();
if (comps.length == 1) {
switch (comps.first) {
case RootDir():
case Prefix():
return None;
case ParentDir():
case CurDir():
case Normal():
return Some(Path(""));
}
}
if (comps.length > 1) {
comps.removeLast();
} else {
return None;
}
return Some(_joinComponents(comps));
}