@@ -318,21 +318,21 @@ maybeFile (ParentIn _) = Nothing
318
318
maybeFile (FileIn p f) = (</>) <$> maybeDir p <*> Just (file' f)
319
319
maybeFile (DirIn _ _) = Nothing
320
320
321
+ -- | Determines if the path is relatively or absolutely specified.
322
+ eitherRelAbs :: forall a b s . Path a b s -> Either (Path Rel b s ) (Path Abs b s )
323
+ eitherRelAbs Current = Left Current
324
+ eitherRelAbs Root = Right Root
325
+ eitherRelAbs (ParentIn p) = bimap (ParentIn ) (ParentIn ) (eitherRelAbs p)
326
+ eitherRelAbs (FileIn p f) = bimap (flip FileIn f) (flip FileIn f) (eitherRelAbs p)
327
+ eitherRelAbs (DirIn p d) = bimap (flip DirIn d) (flip DirIn d) (eitherRelAbs p)
328
+
321
329
-- | Determines if the path is relatively specified.
322
330
maybeRel :: forall a b s . Path a b s -> Maybe (Path Rel b s )
323
- maybeRel Current = Just Current
324
- maybeRel Root = Nothing
325
- maybeRel (ParentIn p) = ParentIn <$> maybeRel p
326
- maybeRel (FileIn p f) = flip FileIn f <$> maybeRel p
327
- maybeRel (DirIn p d) = flip DirIn d <$> maybeRel p
331
+ maybeRel = eitherRelAbs >>> either Just (const Nothing )
328
332
329
333
-- | Determines if the path is absolutely specified.
330
- maybeAbs :: forall a b s . Path a b s -> Maybe (Path Rel b s )
331
- maybeAbs Current = Nothing
332
- maybeAbs Root = Just Root
333
- maybeAbs (ParentIn p) = ParentIn <$> maybeAbs p
334
- maybeAbs (FileIn p f) = flip FileIn f <$> maybeAbs p
335
- maybeAbs (DirIn p d) = flip DirIn d <$> maybeAbs p
334
+ maybeAbs :: forall a b s . Path a b s -> Maybe (Path Abs b s )
335
+ maybeAbs = eitherRelAbs >>> either (const Nothing ) Just
336
336
337
337
-- | Returns the depth of the path. This may be negative in some cases, e.g.
338
338
-- | `./../../../` has depth `-3`.
0 commit comments