-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | An either monad transformer -- @package either @version 4.3.2 -- | Monoidal Validation sibling to Either. module Data.Either.Validation -- | Validation is Either with a Left that is a Monoid data Validation e a Failure :: e -> Validation e a Success :: a -> Validation e a _Success :: Prism (Validation c a) (Validation c b) a b _Failure :: Prism (Validation a c) (Validation b c) a b eitherToValidation :: Either e a -> Validation e a validationToEither :: Validation e a -> Either e a -- | Validation is isomorphic to Either _Validation :: Iso (Validation e a) (Validation g b) (Either e a) (Either g b) instance (Eq e, Eq a) => Eq (Validation e a) instance (Ord e, Ord a) => Ord (Validation e a) instance (Show e, Show a) => Show (Validation e a) instance Monoid e => Monoid (Validation e a) instance Semigroup e => Semigroup (Validation e a) instance Bitraversable Validation instance Bifoldable Validation instance Bifunctor Validation instance Traversable (Validation e) instance Foldable (Validation e) instance (Semigroup e, Monoid e) => Alternative (Validation e) instance Alt (Validation e) instance Semigroup e => Applicative (Validation e) instance Functor (Validation e) -- | Functions for probing and unwrapping values inside of Either. -- -- Most of these combinators are provided for pedagogical purposes and -- exist in more general forms in other libraries. To that end -- alternative definitions are supplied below. module Data.Either.Combinators -- | The isLeft function returns True iff its argument is of -- the form Left _. -- -- Using Control.Lens: -- --
--   isLeft ≡ has _Left
--   
-- --
--   >>> isLeft (Left 12)
--   True
--   
-- --
--   >>> isLeft (Right 12)
--   False
--   
isLeft :: Either a b -> Bool -- | The isRight function returns True iff its argument is of -- the form Right _. -- -- Using Control.Lens: -- --
--   isRight ≡ has _Right
--   
-- --
--   >>> isRight (Left 12)
--   False
--   
-- --
--   >>> isRight (Right 12)
--   True
--   
isRight :: Either a b -> Bool -- | Extract the left value or a default. -- --
--   fromLefteither id
--   
-- --
--   >>> fromLeft "hello" (Right 42)
--   "hello"
--   
-- --
--   >>> fromLeft "hello" (Left "world")
--   "world"
--   
fromLeft :: a -> Either a b -> a -- | Extract the right value or a default. -- --
--   fromRight b ≡ either b id
--   
-- --
--   >>> fromRight "hello" (Right "world")
--   "world"
--   
-- --
--   >>> fromRight "hello" (Left 42)
--   "hello"
--   
fromRight :: b -> Either a b -> b -- | Extracts the element out of a Left and throws an error if its -- argument take the form Right _. -- -- Using Control.Lens: -- --
--   fromLeft' x ≡ x^?!_Left
--   
-- --
--   >>> fromLeft' (Left 12)
--   12
--   
fromLeft' :: Either a b -> a -- | Extracts the element out of a Right and throws an error if its -- argument take the form Left _. -- -- Using Control.Lens: -- --
--   fromRight' x ≡ x^?!_Right
--   
-- --
--   >>> fromRight' (Right 12)
--   12
--   
fromRight' :: Either a b -> b -- | The mapBoth function takes two functions and applies the first -- if iff the value takes the form Left _ and the second -- if the value takes the form Right _. -- -- Using Data.Bifunctor: -- --
--   mapBoth = bimap
--   
-- -- Using Control.Arrow: -- --
--   mapBoth = (+++)
--   
-- --
--   >>> mapBoth (*2) (*3) (Left 4)
--   Left 8
--   
-- --
--   >>> mapBoth (*2) (*3) (Right 4)
--   Right 12
--   
mapBoth :: (a -> c) -> (b -> d) -> Either a b -> Either c d -- | The mapLeft function takes a function and applies it to an -- Either value iff the value takes the form Left _. -- -- Using Data.Bifunctor: -- --
--   mapLeft = first
--   
-- -- Using Control.Arrow: -- --
--   mapLeft = (left)
--   
-- -- Using Control.Lens: -- --
--   mapLeft = over _Left
--   
-- --
--   >>> mapLeft (*2) (Left 4)
--   Left 8
--   
-- --
--   >>> mapLeft (*2) (Right "hello")
--   Right "hello"
--   
mapLeft :: (a -> c) -> Either a b -> Either c b -- | The mapRight function takes a function and applies it to an -- Either value iff the value takes the form Right _. -- -- Using Data.Bifunctor: -- --
--   mapRight = second
--   
-- -- Using Control.Arrow: -- --
--   mapRight = (right)
--   
-- -- Using Control.Lens: -- --
--   mapRight = over _Right
--   
-- --
--   >>> mapRight (*2) (Left "hello")
--   Left "hello"
--   
-- --
--   >>> mapRight (*2) (Right 4)
--   Right 8
--   
mapRight :: (b -> c) -> Either a b -> Either a c -- | The whenLeft function takes an Either value and a -- function which returns a monad. The monad is only executed when the -- given argument takes the form Left _, otherwise it -- does nothing. -- -- Using Control.Lens: -- --
--   whenLeft ≡ forOf_ _Left
--   
-- --
--   >>> whenLeft (Left 12) print
--   12
--   
whenLeft :: Applicative m => Either a b -> (a -> m ()) -> m () -- | The whenRight function takes an Either value and a -- function which returns a monad. The monad is only executed when the -- given argument takes the form Right _, otherwise it -- does nothing. -- -- Using Data.Foldable: -- --
--   whenRightforM_
--   
-- -- Using Control.Lens: -- --
--   whenRight ≡ forOf_ _Right
--   
-- --
--   >>> whenRight (Right 12) print
--   12
--   
whenRight :: Applicative m => Either a b -> (b -> m ()) -> m () -- | A synonym of whenRight. unlessLeft :: Applicative m => Either a b -> (b -> m ()) -> m () -- | A synonym of whenLeft. unlessRight :: Applicative m => Either a b -> (a -> m ()) -> m () -- | Maybe get the Left side of an Either. -- --
--   leftToMaybeeither Just (const Nothing)
--   
-- -- Using Control.Lens: -- --
--   leftToMaybe ≡ preview _Left
--   leftToMaybe x ≡ x^?_Left
--   
-- --
--   >>> leftToMaybe (Left 12)
--   Just 12
--   
-- --
--   >>> leftToMaybe (Right 12)
--   Nothing
--   
leftToMaybe :: Either a b -> Maybe a -- | Maybe get the Right side of an Either. -- --
--   rightToMaybeeither (const Nothing) Just
--   
-- -- Using Control.Lens: -- --
--   rightToMaybe ≡ preview _Right
--   rightToMaybe x ≡ x^?_Right
--   
-- --
--   >>> rightToMaybe (Left 12)
--   Nothing
--   
-- --
--   >>> rightToMaybe (Right 12)
--   Just 12
--   
rightToMaybe :: Either a b -> Maybe b -- | This module provides a minimalist Either monad transformer. module Control.Monad.Trans.Either -- | EitherT is a version of ErrorT that does not require a -- spurious Error instance for the Left case. -- -- Either is a perfectly usable Monad without such a -- constraint. ErrorT is not the generalization of the current -- Either monad, it is something else. -- -- This is necessary for both theoretical and practical reasons. For -- instance an apomorphism is the generalized anamorphism for this Monad, -- but it cannot be written with ErrorT. -- -- In addition to the combinators here, the errors package -- provides a large number of combinators for working with this type. newtype EitherT e m a EitherT :: m (Either e a) -> EitherT e m a runEitherT :: EitherT e m a -> m (Either e a) -- | Given a pair of actions, one to perform in case of failure, and one to -- perform in case of success, run an EitherT and get back a -- monadic result. eitherT :: Monad m => (a -> m c) -> (b -> m c) -> EitherT a m b -> m c -- | Map over both failure and success. bimapEitherT :: Functor m => (e -> f) -> (a -> b) -> EitherT e m a -> EitherT f m b -- | Map the unwrapped computation using the given function. -- --
--   runEitherT (mapEitherT f m) = f (runEitherT m)
--   
mapEitherT :: (m (Either e a) -> n (Either e' b)) -> EitherT e m a -> EitherT e' n b -- | Lift an Either into an EitherT hoistEither :: Monad m => Either e a -> EitherT e m a -- | Analogous to Left. Equivalent to throwError. left :: Monad m => e -> EitherT e m a -- | Analogous to Right. Equivalent to return. right :: Monad m => a -> EitherT e m a instance MonadBaseControl b m => MonadBaseControl b (EitherT e m) instance MonadTransControl (EitherT e) instance MonadBase b m => MonadBase b (EitherT e m) instance (Monad f, Traversable f) => Traversable (EitherT e f) instance (Functor f, MonadFree f m) => MonadFree f (EitherT e m) instance Foldable m => Foldable (EitherT e m) instance MonadRandom m => MonadRandom (EitherT e m) instance MonadWriter s m => MonadWriter s (EitherT e m) instance MonadState s m => MonadState s (EitherT e m) instance MonadReader r m => MonadReader r (EitherT e m) instance MonadCont m => MonadCont (EitherT e m) instance MonadIO m => MonadIO (EitherT e m) instance MonadTrans (EitherT e) instance MonadFix m => MonadFix (EitherT e m) instance MonadCatch m => MonadCatch (EitherT e m) instance MonadThrow m => MonadThrow (EitherT e m) instance Monad m => MonadError e (EitherT e m) instance Monad m => Monad (EitherT e m) instance Monad m => Bind (EitherT e m) instance (Monad m, Semigroup e) => Alt (EitherT e m) instance Monad m => Semigroup (EitherT e m a) instance (Monad m, Monoid e) => MonadPlus (EitherT e m) instance (Monad m, Monoid e) => Alternative (EitherT e m) instance Monad m => Applicative (EitherT e m) instance Monad m => Apply (EitherT e m) instance Monad m => Functor (EitherT e m) instance Ord (m (Either e a)) => Ord (EitherT e m a) instance Eq (m (Either e a)) => Eq (EitherT e m a) instance Read (m (Either e a)) => Read (EitherT e m a) instance Show (m (Either e a)) => Show (EitherT e m a)