move
This commit is contained in:
parent
95d2391f58
commit
9901fc04a0
2 changed files with 12 additions and 7 deletions
|
@ -7,7 +7,8 @@
|
||||||
|
|
||||||
module Utility.BadPrelude where
|
module Utility.BadPrelude where
|
||||||
|
|
||||||
{- read should be avoided, as it throws an error -}
|
{- read should be avoided, as it throws an error
|
||||||
|
- Instead, use: readMaybe -}
|
||||||
read :: Read a => String -> a
|
read :: Read a => String -> a
|
||||||
read = Prelude.read
|
read = Prelude.read
|
||||||
|
|
||||||
|
@ -31,6 +32,16 @@ init = Prelude.init
|
||||||
last :: [a] -> a
|
last :: [a] -> a
|
||||||
last = Prelude.last
|
last = Prelude.last
|
||||||
|
|
||||||
|
{- Attempts to read a value from a String.
|
||||||
|
-
|
||||||
|
- Ignores leading/trailing whitespace, and throws away any trailing
|
||||||
|
- text after the part that can be read.
|
||||||
|
-}
|
||||||
|
readMaybe :: (Read a) => String -> Maybe a
|
||||||
|
readMaybe s = case reads s of
|
||||||
|
((x,_):_) -> Just x
|
||||||
|
_ -> Nothing
|
||||||
|
|
||||||
{- 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 [] = Nothing
|
||||||
|
|
|
@ -21,12 +21,6 @@ hGetContentsStrict = hGetContents >=> \s -> length s `seq` return s
|
||||||
readFileStrict :: FilePath -> IO String
|
readFileStrict :: FilePath -> IO String
|
||||||
readFileStrict = readFile >=> \s -> length s `seq` return s
|
readFileStrict = readFile >=> \s -> length s `seq` return s
|
||||||
|
|
||||||
{- Attempts to read a value from a String. -}
|
|
||||||
readMaybe :: (Read a) => String -> Maybe a
|
|
||||||
readMaybe s = case reads s of
|
|
||||||
((x,_):_) -> Just x
|
|
||||||
_ -> Nothing
|
|
||||||
|
|
||||||
{- Like break, but the character matching the condition is not included
|
{- Like break, but the character matching the condition is not included
|
||||||
- in the second result list.
|
- in the second result list.
|
||||||
-
|
-
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue