transformers-either 0.0.1 → 0.0.2
raw patch · 2 files changed
+42/−3 lines, 2 filesdep +text
Dependencies added: text
Files
+ src/Control/Monad/Trans/Either/Exit.hs view
@@ -0,0 +1,37 @@+module Control.Monad.Trans.Either.Exit (+ orDie+ , orDieWithCode+ ) where++import Control.Applicative (pure)+import Control.Monad ((>>=), (>>))++import Data.Either (either)+import Data.Function ((.))+import Data.Int (Int)+import Data.Text (Text)+import qualified Data.Text as T++import System.Exit (ExitCode(..), exitWith)+import System.IO (IO, stderr, hPutStrLn)++import Control.Monad.Trans.Either+++-- | orDieWithCode with an exit code of 1 in case of an error+--+orDie :: (e -> Text) -> EitherT e IO a -> IO a+orDie = orDieWithCode 1++-- | An idiom for failing hard on EitherT errors.+--+-- *This really dies*. There is no other way to say it.+--+-- The reason it lives with command line parser tooling, is that it is+-- the only valid place to actually exit like this. Be appropriately+-- wary.+--+orDieWithCode :: Int -> (e -> Text) -> EitherT e IO a -> IO a+orDieWithCode code render e =+ runEitherT e >>=+ either (\err -> (hPutStrLn stderr . T.unpack . render) err >> exitWith (ExitFailure code)) pure
transformers-either.cabal view
@@ -1,5 +1,5 @@ name: transformers-either-version: 0.0.1+version: 0.0.2 license: BSD3 license-file: LICENSE author: Tim McGilchrist <timmcgil@gmail.com>@@ -14,14 +14,15 @@ Uses a pattern synonym to maintain compatibility with the old EitherT types but is actually ExceptT under the covers.- + source-repository head type: git location: https://github.com/tmcgilchrist/transformers-either.git- + library build-depends: base >= 3 && < 5+ , text == 1.2.* , transformers >= 0.4 && < 0.6 ghc-options:@@ -32,3 +33,4 @@ exposed-modules: Control.Monad.Trans.Either+ Control.Monad.Trans.Either.Exit