summaryrefslogtreecommitdiff
path: root/Presence/ControlMaybe.hs
blob: 4d9d713fd7f59067f60db9f8979c8c82bef65fac (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
{-# LANGUAGE ScopedTypeVariables #-}
module ControlMaybe where

-- import GHC.IO.Exception (IOException(..))
import Control.Monad
import Control.Exception as Exception (IOException(..),catch)
import System.IO.Error


-- forM_ with less polymorphism.
withJust :: Monad m => Maybe x -> (x -> m ()) -> m ()
withJust m f = forM_ m f
{-# INLINE withJust #-}

whenJust :: Monad m => m (Maybe x) -> (x -> m ()) -> m ()
whenJust acn f = acn >>= mapM_ f
{-# INLINE whenJust #-}


catchIO_ :: IO a -> IO a -> IO a
catchIO_ body catcher = catchIOError body (\_ -> catcher)
{-# INLINE catchIO_ #-}

handleIO_ :: IO a -> IO a -> IO a
handleIO_ catcher body = catchIOError body (\_ -> catcher)
{-# INLINE handleIO_ #-}


handleIO :: (IOError -> IO a) -> IO a -> IO a
handleIO catcher body = catchIOError body catcher
{-# INLINE handleIO #-}