Copyright | © 2016 Julian Ospald |
---|---|
License | BSD3 |
Maintainer | Julian Ospald <hasufell@posteo.de> |
Stability | experimental |
Portability | portable |
Safe Haskell | Safe |
Language | Haskell2010 |
Random and general IO/monad utilities.
diff --git a/HPath-IO-Utils.html b/HPath-IO-Utils.html deleted file mode 100644 index c44844c..0000000 --- a/HPath-IO-Utils.html +++ /dev/null @@ -1,6 +0,0 @@ -
Copyright | © 2016 Julian Ospald |
---|---|
License | BSD3 |
Maintainer | Julian Ospald <hasufell@posteo.de> |
Stability | experimental |
Portability | portable |
Safe Haskell | Safe |
Language | Haskell2010 |
Random and general IO/monad utilities.
>>>
basename (MkPath "/") :: Maybe (Path Fn)
Nothing
-dirname :: Path Abs -> Path Abs Source #
Extract the directory name of a path.
The following properties hold:
dirname (p </> a) == dirname p
>>>
dirname (MkPath "/abc/def/dod") +
dirname :: Path Abs -> Path Abs Source #
Extract the directory name of a path.
>>>
dirname (MkPath "/abc/def/dod")
"/abc/def">>>
dirname (MkPath "/")
"/" diff --git a/hpath.haddock b/hpath.haddock index a0cd060..b15b592 100644 Binary files a/hpath.haddock and b/hpath.haddock differ diff --git a/mini_HPath-IO-Utils.html b/mini_HPath-IO-Utils.html deleted file mode 100644 index 1ce788b..0000000 --- a/mini_HPath-IO-Utils.html +++ /dev/null @@ -1,4 +0,0 @@ -HPath.IO.Utils \ No newline at end of file diff --git a/src/HPath-IO-Utils.html b/src/HPath-IO-Utils.html deleted file mode 100644 index 0846c71..0000000 --- a/src/HPath-IO-Utils.html +++ /dev/null @@ -1,43 +0,0 @@ - - - - - -src/HPath/IO/Utils.hs - - - --- | --- Module : HPath.IO.Utils --- Copyright : © 2016 Julian Ospald --- License : BSD3 --- --- Maintainer : Julian Ospald <hasufell@posteo.de> --- Stability : experimental --- Portability : portable --- --- Random and general IO/monad utilities. - - -module HPath.IO.Utils where - - -import Control.Monad - ( - when - , unless - ) - - --- |If the value of the first argument is True, then execute the action --- provided in the second argument, otherwise do nothing. -whenM :: Monad m => m Bool -> m () -> m () -whenM mb a = mb >>= (`when` a) - - --- |If the value of the first argument is False, then execute the action --- provided in the second argument, otherwise do nothing. -unlessM :: Monad m => m Bool -> m () -> m () -unlessM mb a = mb >>= (`unless` a) -- diff --git a/src/HPath.html b/src/HPath.html index a5f5bf8..3ce1e3b 100644 --- a/src/HPath.html +++ b/src/HPath.html @@ -323,63 +323,59 @@ -- | Extract the directory name of a path. -- --- The following properties hold: --- --- @dirname (p \<\/> a) == dirname p@ --- --- >>> dirname (MkPath "/abc/def/dod") --- "/abc/def" --- >>> dirname (MkPath "/") --- "/" -dirname :: Path Abs -> Path Abs -dirname (MkPath fp) = MkPath (takeDirectory $ dropTrailingPathSeparator fp) - --- | Extract the file part of a path. --- +-- >>> dirname (MkPath "/abc/def/dod") +-- "/abc/def" +-- >>> dirname (MkPath "/") +-- "/" +dirname :: Path Abs -> Path Abs +dirname (MkPath fp) = MkPath (takeDirectory $ dropTrailingPathSeparator fp) + +-- | Extract the file part of a path. +-- +-- +-- The following properties hold: +-- +-- @basename (p \<\/> a) == basename a@ -- --- The following properties hold: +-- Throws: `PathException` if given the root path "/" -- --- @basename (p \<\/> a) == basename a@ --- --- Throws: `PathException` if given the root path "/" --- --- >>> basename (MkPath "/abc/def/dod") :: Maybe (Path Fn) --- Just "dod" --- >>> basename (MkPath "/abc/def/dod/") :: Maybe (Path Fn) --- Just "dod" --- >>> basename (MkPath "/") :: Maybe (Path Fn) --- Nothing -basename :: MonadThrow m => Path b -> m (Path Fn) -basename (MkPath l) - | not (isAbsolute rl) = return $ MkPath rl - | otherwise = throwM RootDirHasNoBasename - where - rl = last . splitPath . dropTrailingPathSeparator $ l +-- >>> basename (MkPath "/abc/def/dod") :: Maybe (Path Fn) +-- Just "dod" +-- >>> basename (MkPath "/abc/def/dod/") :: Maybe (Path Fn) +-- Just "dod" +-- >>> basename (MkPath "/") :: Maybe (Path Fn) +-- Nothing +basename :: MonadThrow m => Path b -> m (Path Fn) +basename (MkPath l) + | not (isAbsolute rl) = return $ MkPath rl + | otherwise = throwM RootDirHasNoBasename + where + rl = last . splitPath . dropTrailingPathSeparator $ l + + +-------------------------------------------------------------------------------- +-- Path IO helpers --------------------------------------------------------------------------------- --- Path IO helpers +withAbsPath :: Path Abs -> (ByteString -> IO a) -> IO a +withAbsPath (MkPath p) action = action p -withAbsPath :: Path Abs -> (ByteString -> IO a) -> IO a -withAbsPath (MkPath p) action = action p +withRelPath :: Path Rel -> (ByteString -> IO a) -> IO a +withRelPath (MkPath p) action = action p -withRelPath :: Path Rel -> (ByteString -> IO a) -> IO a -withRelPath (MkPath p) action = action p +withFnPath :: Path Fn -> (ByteString -> IO a) -> IO a +withFnPath (MkPath p) action = action p -withFnPath :: Path Fn -> (ByteString -> IO a) -> IO a -withFnPath (MkPath p) action = action p +------------------------ +-- ByteString helpers - ------------------------- --- ByteString helpers - -#if MIN_VERSION_bytestring(0,10,8) -#else -stripPrefix :: ByteString -> ByteString -> Maybe ByteString -stripPrefix a b = BS.pack `fmap` L.stripPrefix (BS.unpack a) (BS.unpack b) -#endif +#if MIN_VERSION_bytestring(0,10,8) +#else +stripPrefix :: ByteString -> ByteString -> Maybe ByteString +stripPrefix a b = BS.pack `fmap` L.stripPrefix (BS.unpack a) (BS.unpack b) +#endif