summaryrefslogtreecommitdiff
path: root/Presence/ControlMaybe.hs
blob: 659dab746f795bcd1366fe6fa2f5433502d5745b (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
{-# LANGUAGE ScopedTypeVariables #-}
module ControlMaybe where

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


withJust :: Monad m => Maybe x -> (x -> m ()) -> m ()
withJust (Just x) f = f x
withJust Nothing  f = return ()

whenJust :: Monad m => m (Maybe x) -> (x -> m ()) -> m ()
whenJust acn f = do
    x <- acn
    withJust x f


catchIO_ :: IO a -> IO a -> IO a
catchIO_ a h = Exception.catch a (\(_ :: IOException) -> h)

catchIO :: IO a -> (IOException -> IO a)  -> IO a
catchIO body handler = Exception.catch body handler

handleIO_ :: IO a -> IO a -> IO a
handleIO_ = flip catchIO_


handleIO :: (IOException -> IO a) -> IO a -> IO a
handleIO = flip catchIO