Generalize stripDir to MonadThrow

This commit is contained in:
Chris Done 2015-05-22 11:32:57 +02:00
parent 87a56a93b8
commit ffdf4af243
1 changed files with 7 additions and 2 deletions

View File

@ -239,9 +239,14 @@ toFilePath (Path l) = l
--
-- In other words the bases must match.
--
stripDir :: Path b Dir -> Path b t -> Maybe (Path Rel t)
-- Throws: 'Couldn'tStripPrefixDir'
--
stripDir :: MonadThrow m
=> Path b Dir -> Path b t -> m (Path Rel t)
stripDir (Path p) (Path l) =
fmap Path (stripPrefix p l)
case fmap Path (stripPrefix p l) of
Nothing -> throwM (Couldn'tStripPrefixDir p l)
Just ok -> return ok
-- | Is p a parent of the given location? Implemented in terms of
-- 'stripDir'. The bases must match.