path-utils-0.1.0.0: src/Path/Utils.hs
{- |
Module : Path.Utils
License : MIT
Stability : experimental
Miscellaneous utility functions for the path library.
-}
module Path.Utils (
(</$>)
, changeDir
, splitPath
) where
import Control.Monad.Catch
import qualified Data.Text as T
import Data.Text (Text)
import Data.List.Split
import Path
-- | Apply `(</>)` to every relative path inside a functor.
(</$>) :: Functor f => Path b Dir -> f (Path Rel t) -> f (Path b t)
(</$>) d = fmap (d </>)
-- | Change directory from src to dst.
changeDir :: MonadThrow m => Path b Dir -> Path b' Dir -> Path b t -> m (Path b' t)
changeDir src dst fp = (dst </>) <$> stripProperPrefix src fp
-- | Split a relative path into text sections.
splitPath :: Path Rel t -> [Text]
splitPath = fmap T.pack . splitOn "/" . toFilePath