summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Presence/ControlMaybe.hs26
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 @@
2module ControlMaybe where 2module ControlMaybe where
3 3
4-- import GHC.IO.Exception (IOException(..)) 4-- import GHC.IO.Exception (IOException(..))
5import Control.Monad
5import Control.Exception as Exception (IOException(..),catch) 6import Control.Exception as Exception (IOException(..),catch)
7import System.IO.Error
6 8
7 9
10-- forM_ with less polymorphism.
8withJust :: Monad m => Maybe x -> (x -> m ()) -> m () 11withJust :: Monad m => Maybe x -> (x -> m ()) -> m ()
9withJust (Just x) f = f x 12withJust m f = forM_ m f
10withJust Nothing f = return () 13{-# INLINE withJust #-}
11 14
12whenJust :: Monad m => m (Maybe x) -> (x -> m ()) -> m () 15whenJust :: Monad m => m (Maybe x) -> (x -> m ()) -> m ()
13whenJust acn f = do 16whenJust acn f = acn >>= mapM_ f
14 x <- acn 17{-# INLINE whenJust #-}
15 withJust x f
16 18
17 19
18catchIO_ :: IO a -> IO a -> IO a 20catchIO_ :: IO a -> IO a -> IO a
19catchIO_ a h = Exception.catch a (\(_ :: IOException) -> h) 21catchIO_ body catcher = catchIOError body (\_ -> catcher)
20 22{-# INLINE catchIO_ #-}
21catchIO :: IO a -> (IOException -> IO a) -> IO a
22catchIO body handler = Exception.catch body handler
23 23
24handleIO_ :: IO a -> IO a -> IO a 24handleIO_ :: IO a -> IO a -> IO a
25handleIO_ = flip catchIO_ 25handleIO_ catcher body = catchIOError body (\_ -> catcher)
26{-# INLINE handleIO_ #-}
26 27
27 28
28handleIO :: (IOException -> IO a) -> IO a -> IO a 29handleIO :: (IOError -> IO a) -> IO a -> IO a
29handleIO = flip catchIO 30handleIO catcher body = catchIOError body catcher
31{-# INLINE handleIO #-}