slackbuilder/lib/SlackBuilder/Trans.hs
Eugen Wissner eb68629653
All checks were successful
Build / audit (push) Successful in 16m16s
Build / test (push) Successful in 15m47s
Support x86-64 only downloads
2023-12-12 18:51:44 +01:00

49 lines
1.3 KiB
Haskell

-- | Transformers and exceptions.
module SlackBuilder.Trans
( SlackBuilderException(..)
, SlackBuilderT(..)
) where
import Control.Monad.Trans.Reader (ReaderT(..))
import Data.Text (Text)
import SlackBuilder.Config
import Control.Monad.IO.Class (MonadIO(..))
import Control.Monad.Catch (MonadCatch(..), MonadThrow(..))
import Control.Exception (Exception(..))
newtype SlackBuilderException = UpdaterNotFound Text
deriving Show
instance Exception SlackBuilderException
newtype SlackBuilderT a = SlackBuilderT
{ runSlackBuilderT :: ReaderT Settings IO a
}
instance Functor SlackBuilderT
where
fmap f (SlackBuilderT slackBuilderT) = SlackBuilderT $ f <$> slackBuilderT
instance Applicative SlackBuilderT
where
pure = SlackBuilderT . pure
(SlackBuilderT f) <*> (SlackBuilderT x) = SlackBuilderT $ f <*> x
instance Monad SlackBuilderT
where
return = pure
(SlackBuilderT x) >>= f = SlackBuilderT $ x >>= runSlackBuilderT . f
instance MonadIO SlackBuilderT
where
liftIO = SlackBuilderT . liftIO
instance MonadThrow SlackBuilderT
where
throwM = SlackBuilderT . throwM
instance MonadCatch SlackBuilderT
where
catch (SlackBuilderT action) handler =
SlackBuilderT $ catch action $ runSlackBuilderT . handler