a few things available elsewhere...
This commit is contained in:
parent
bed495db64
commit
5e172b43c4
2 changed files with 10 additions and 3 deletions
|
@ -7,6 +7,8 @@
|
||||||
|
|
||||||
module Utility.PartialPrelude where
|
module Utility.PartialPrelude where
|
||||||
|
|
||||||
|
import qualified Data.Maybe
|
||||||
|
|
||||||
{- read should be avoided, as it throws an error
|
{- read should be avoided, as it throws an error
|
||||||
- Instead, use: readMaybe -}
|
- Instead, use: readMaybe -}
|
||||||
read :: Read a => String -> a
|
read :: Read a => String -> a
|
||||||
|
@ -36,6 +38,9 @@ last = Prelude.last
|
||||||
-
|
-
|
||||||
- Ignores leading/trailing whitespace, and throws away any trailing
|
- Ignores leading/trailing whitespace, and throws away any trailing
|
||||||
- text after the part that can be read.
|
- text after the part that can be read.
|
||||||
|
-
|
||||||
|
- readMaybe is available in Text.Read in new versions of GHC,
|
||||||
|
- but that one requires the entire string to be consumed.
|
||||||
-}
|
-}
|
||||||
readMaybe :: Read a => String -> Maybe a
|
readMaybe :: Read a => String -> Maybe a
|
||||||
readMaybe s = case reads s of
|
readMaybe s = case reads s of
|
||||||
|
@ -44,8 +49,7 @@ readMaybe s = case reads s of
|
||||||
|
|
||||||
{- Like head but Nothing on empty list. -}
|
{- Like head but Nothing on empty list. -}
|
||||||
headMaybe :: [a] -> Maybe a
|
headMaybe :: [a] -> Maybe a
|
||||||
headMaybe [] = Nothing
|
headMaybe = Data.Maybe.listToMaybe
|
||||||
headMaybe v = Just $ Prelude.head v
|
|
||||||
|
|
||||||
{- Like last but Nothing on empty list. -}
|
{- Like last but Nothing on empty list. -}
|
||||||
lastMaybe :: [a] -> Maybe a
|
lastMaybe :: [a] -> Maybe a
|
||||||
|
|
|
@ -47,7 +47,10 @@ dirContains a b = a == b || a' == b' || (a'++"/") `isPrefixOf` b'
|
||||||
a' = norm a
|
a' = norm a
|
||||||
b' = norm b
|
b' = norm b
|
||||||
|
|
||||||
{- Converts a filename into a normalized, absolute path. -}
|
{- Converts a filename into a normalized, absolute path.
|
||||||
|
-
|
||||||
|
- Unlike Directory.canonicalizePath, this does not require the path
|
||||||
|
- already exists. -}
|
||||||
absPath :: FilePath -> IO FilePath
|
absPath :: FilePath -> IO FilePath
|
||||||
absPath file = do
|
absPath file = do
|
||||||
cwd <- getCurrentDirectory
|
cwd <- getCurrentDirectory
|
||||||
|
|
Loading…
Reference in a new issue