module Data.Conduit.Shell.Types where
import Control.Applicative
import UnliftIO.Exception
import Control.Monad
import Control.Monad.IO.Class
import Control.Monad.Trans.Class
import Control.Monad.Trans.Resource
import Data.Conduit
import Data.Typeable
newtype ShellT m a = ShellT
{ runShellT :: ResourceT m a
} deriving (Applicative, Monad, Functor, MonadThrow, MonadIO, MonadTrans)
deriving instance (MonadUnliftIO m) => MonadResource (ShellT m)
instance (MonadUnliftIO (ShellT m), Applicative m, MonadThrow m) =>
Alternative (ConduitT i o (ShellT m)) where
empty = throwIO ShellEmpty
x <|> y = do
r <- tryC x
case r of
Left (_ :: ShellException) -> y
Right rr -> return rr
data ShellException
= ShellEmpty
| ShellExitFailure !Int
deriving (Typeable, Show)
instance Exception ShellException