diff options
author | joe <joe@jerkface.net> | 2018-06-01 16:30:25 -0400 |
---|---|---|
committer | joe <joe@jerkface.net> | 2018-06-01 16:30:25 -0400 |
commit | f43dab6b76a5c6022457831caac79c861a91f9ae (patch) | |
tree | 7e0273e331d39a57de90447c841eabac491ea10a /Presence | |
parent | 248c19df2a894db002f8c00301dcf755f926da4e (diff) |
Minor modernization of ControlMaybe utilities.
Diffstat (limited to 'Presence')
-rw-r--r-- | Presence/ControlMaybe.hs | 26 |
1 files changed, 14 insertions, 12 deletions
diff --git a/Presence/ControlMaybe.hs b/Presence/ControlMaybe.hs index 659dab74..4d9d713f 100644 --- a/Presence/ControlMaybe.hs +++ b/Presence/ControlMaybe.hs | |||
@@ -2,28 +2,30 @@ | |||
2 | module ControlMaybe where | 2 | module ControlMaybe where |
3 | 3 | ||
4 | -- import GHC.IO.Exception (IOException(..)) | 4 | -- import GHC.IO.Exception (IOException(..)) |
5 | import Control.Monad | ||
5 | import Control.Exception as Exception (IOException(..),catch) | 6 | import Control.Exception as Exception (IOException(..),catch) |
7 | import System.IO.Error | ||
6 | 8 | ||
7 | 9 | ||
10 | -- forM_ with less polymorphism. | ||
8 | withJust :: Monad m => Maybe x -> (x -> m ()) -> m () | 11 | withJust :: Monad m => Maybe x -> (x -> m ()) -> m () |
9 | withJust (Just x) f = f x | 12 | withJust m f = forM_ m f |
10 | withJust Nothing f = return () | 13 | {-# INLINE withJust #-} |
11 | 14 | ||
12 | whenJust :: Monad m => m (Maybe x) -> (x -> m ()) -> m () | 15 | whenJust :: Monad m => m (Maybe x) -> (x -> m ()) -> m () |
13 | whenJust acn f = do | 16 | whenJust acn f = acn >>= mapM_ f |
14 | x <- acn | 17 | {-# INLINE whenJust #-} |
15 | withJust x f | ||
16 | 18 | ||
17 | 19 | ||
18 | catchIO_ :: IO a -> IO a -> IO a | 20 | catchIO_ :: IO a -> IO a -> IO a |
19 | catchIO_ a h = Exception.catch a (\(_ :: IOException) -> h) | 21 | catchIO_ body catcher = catchIOError body (\_ -> catcher) |
20 | 22 | {-# INLINE catchIO_ #-} | |
21 | catchIO :: IO a -> (IOException -> IO a) -> IO a | ||
22 | catchIO body handler = Exception.catch body handler | ||
23 | 23 | ||
24 | handleIO_ :: IO a -> IO a -> IO a | 24 | handleIO_ :: IO a -> IO a -> IO a |
25 | handleIO_ = flip catchIO_ | 25 | handleIO_ catcher body = catchIOError body (\_ -> catcher) |
26 | {-# INLINE handleIO_ #-} | ||
26 | 27 | ||
27 | 28 | ||
28 | handleIO :: (IOException -> IO a) -> IO a -> IO a | 29 | handleIO :: (IOError -> IO a) -> IO a -> IO a |
29 | handleIO = flip catchIO | 30 | handleIO catcher body = catchIOError body catcher |
31 | {-# INLINE handleIO #-} | ||