errors 1.4.5 → 1.4.6
raw patch · 2 files changed
+53/−8 lines, 2 files
Files
- Control/Error/Util.hs +52/−7
- errors.cabal +1/−1
Control/Error/Util.hs view
@@ -13,10 +13,18 @@ failWith, failWithM, + -- * Bool+ bool,++ -- * Maybe+ (?:),+ -- * MaybeT maybeT, just, nothing,+ isJustT,+ isNothingT, -- * Either isLeft,@@ -26,6 +34,8 @@ AnyE(..), -- * EitherT+ isLeftT,+ isRightT, fmapRT, -- * Error Reporting@@ -34,23 +44,21 @@ -- * Exceptions tryIO,- syncIO + syncIO ) where import Control.Applicative (Applicative, pure, (<$>)) import qualified Control.Exception as Ex import Control.Monad (liftM) import Control.Monad.IO.Class (MonadIO(liftIO))-import Control.Monad.Trans.Either (EitherT(EitherT, runEitherT))+import Control.Monad.Trans.Either (EitherT(EitherT, runEitherT), eitherT) import Control.Monad.Trans.Maybe (MaybeT(MaybeT, runMaybeT)) import Data.Dynamic (Dynamic) import Data.Monoid (Monoid(mempty, mappend))+import Data.Maybe (fromMaybe) import System.Exit (ExitCode) import System.IO (hPutStr, hPutStrLn, stderr) --- For Documentation-import Data.EitherR (fmapL, fmapLT)- {- $conversion Use these functions to convert between 'Maybe', 'Either', 'MaybeT', and 'EitherT'.@@ -85,6 +93,11 @@ (!?) :: Applicative m => m (Maybe a) -> e -> EitherT e m a (!?) a e = EitherT (note e <$> a) +-- | An infix form of 'fromMaybe' with arguments flipped.+(?:) :: Maybe a -> a -> a+maybeA ?: b = fromMaybe b maybeA+{-# INLINABLE (?:) #-}+ {-| Convert a 'Maybe' value into the 'EitherT' monad Named version of ('??') with arguments flipped@@ -99,6 +112,14 @@ failWithM :: Applicative m => e -> m (Maybe a) -> EitherT e m a failWithM e a = a !? e +{- | Case analysis for the 'Bool' type.++ > bool a b c == if c then b else a+-}+bool :: a -> a -> Bool -> a+bool a b = \c -> if c then b else a+{-# INLINABLE bool #-}+ {-| Case analysis for 'MaybeT' Use the first argument if the 'MaybeT' computation fails, otherwise apply@@ -115,6 +136,16 @@ nothing :: (Monad m) => MaybeT m a nothing = MaybeT (return Nothing) +-- | Analogous to 'Data.Maybe.isJust', but for 'MaybeT'+isJustT :: (Monad m) => MaybeT m a -> m Bool+isJustT = maybeT (return False) (\_ -> return True)+{-# INLINABLE isJustT #-}++-- | Analogous to 'Data.Maybe.isNothing', but for 'MaybeT'+isNothingT :: (Monad m) => MaybeT m a -> m Bool+isNothingT = maybeT (return True) (\_ -> return False)+{-# INLINABLE isNothingT #-}+ -- | Returns whether argument is a 'Left' isLeft :: Either a b -> Bool isLeft = either (const True) (const False)@@ -123,7 +154,9 @@ isRight :: Either a b -> Bool isRight = either (const False) (const True) --- | 'fmap' specialized to 'Either', given a name symmetric to 'fmapL'+{- | 'fmap' specialized to 'Either', given a name symmetric to+ 'Data.EitherR.fmapL'+-} fmapR :: (a -> b) -> Either l a -> Either l b fmapR = fmap @@ -153,7 +186,19 @@ mappend (AnyE (Left _)) (AnyE (Right y)) = AnyE (Right y) mappend (AnyE (Left x)) (AnyE (Left y)) = AnyE (Left (mappend x y)) --- | 'fmap' specialized to 'EitherT', given a name symmetric to 'fmapLT'+-- | Analogous to 'isLeft', but for 'EitherT'+isLeftT :: (Monad m) => EitherT a m b -> m Bool+isLeftT = eitherT (\_ -> return True) (\_ -> return False)+{-# INLINABLE isLeftT #-}++-- | Analogous to 'isRight', but for 'EitherT'+isRightT :: (Monad m) => EitherT a m b -> m Bool+isRightT = eitherT (\_ -> return False) (\_ -> return True)+{-# INLINABLE isRightT #-}++{- | 'fmap' specialized to 'EitherT', given a name symmetric to+ 'Data.EitherR.fmapLT'+-} fmapRT :: (Monad m) => (a -> b) -> EitherT l m a -> EitherT l m b fmapRT = liftM
errors.cabal view
@@ -1,5 +1,5 @@ Name: errors-Version: 1.4.5+Version: 1.4.6 Cabal-Version: >=1.8.0.2 Build-Type: Simple License: BSD3