@@ -318,21 +318,21 @@ maybeFile (ParentIn _) = Nothing
318318maybeFile (FileIn p f) = (</>) <$> maybeDir p <*> Just (file' f)
319319maybeFile (DirIn _ _) = Nothing
320320
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+
321329-- | Determines if the path is relatively specified.
322330maybeRel :: 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 )
328332
329333-- | 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
336336
337337-- | Returns the depth of the path. This may be negative in some cases, e.g.
338338-- | `./../../../` has depth `-3`.
0 commit comments