Copyright | (c) Owen Shepherd 2021 |
---|---|
License | MIT |
Maintainer | owen@owen.cafe |
Stability | stable |
Portability | portable |
Safe Haskell | Safe-Inferred |
Language | Haskell2010 |
Errors are accumulated through Applicative
sequencing.
The recommended way to use MultiExcept
is with ApplicativeDo
:
{-# LANGUAGE ApplicativeDo #-} import Control.Applicative.MultiExcept errors :: MultiExcept String (Int, Int, Int) errors = do a <- throwError "no monad instance" b <- pure 12 c <- throwError "i am scared" pure (a, b, c)
Synopsis
- data MultiExcept err a
- fromEither :: Either err a -> MultiExcept err a
- fromEitherPoly :: Either (NonEmpty err) a -> MultiExcept err a
- join :: MultiExcept err (MultiExcept err a) -> MultiExcept err a
- or :: MultiExcept err a -> MultiExcept err a -> MultiExcept err a
- runMultiExcept :: MultiExcept err a -> Either (NonEmpty err) a
- succeed :: forall err a. a -> MultiExcept err a
- throwError :: forall a err. err -> MultiExcept err a
- throwErrors :: forall a err. NonEmpty err -> MultiExcept err a
- mapMultiExcept :: (err -> err') -> (a -> a') -> MultiExcept err a -> MultiExcept err' a'
Documentation
data MultiExcept err a Source #
A MultiExcept
is a success value, or one or more errors.
Instances
fromEither :: Either err a -> MultiExcept err a Source #
Convert an Either
to a MultiExcept
.
fromEitherPoly :: Either (NonEmpty err) a -> MultiExcept err a Source #
Convert a multi-error Either
to a MultiExcept
.
join :: MultiExcept err (MultiExcept err a) -> MultiExcept err a Source #
Join nested MultiExcept
s with the same error type.
Note that this doesn't imply a useful Monad
instance.
The instance defined in terms of join discards errors on the RHS of >>=
,
when the LHS is an error value.
or :: MultiExcept err a -> MultiExcept err a -> MultiExcept err a Source #
Return the first success, or all of the combined errors.
Examples
>>>
pure 1 `or` throwError 3
Success 1
>>>
throwError 2 `or` pure 1
Success 1
>>>
throwError 2 `or` throwError 3
Errors [2, 3]
runMultiExcept :: MultiExcept err a -> Either (NonEmpty err) a Source #
Run the computation.
succeed :: forall err a. a -> MultiExcept err a Source #
Embeds a value into a MultiExcept
context.
throwError :: forall a err. err -> MultiExcept err a Source #
Throw a single error.
throwErrors :: forall a err. NonEmpty err -> MultiExcept err a Source #
Throw one or more errors.
mapMultiExcept :: (err -> err') -> (a -> a') -> MultiExcept err a -> MultiExcept err' a' Source #
A non-overloaded bimap