multi-except 0.1.3.0 → 0.1.4.0
raw patch · 3 files changed
+31/−8 lines, 3 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
+ Control.Applicative.MultiExcept: fromEitherPoly :: Either (DNonEmpty err) a -> MultiExcept err a
+ Control.Applicative.MultiExcept: join :: MultiExcept err (MultiExcept err a) -> MultiExcept err a
+ Control.Applicative.MultiExcept: throwErrors :: DNonEmpty err -> MultiExcept err a
Files
- CHANGELOG.md +4/−0
- Control/Applicative/MultiExcept.hs +26/−7
- multi-except.cabal +1/−1
CHANGELOG.md view
@@ -1,5 +1,9 @@ # Revision history for multi-except +## 0.1.4.0 -- 2021-05-26++* Added join, fromEitherPoly, throwErrors+ ## 0.1.3.0 -- 2021-05-26 * Exposed fromEither
Control/Applicative/MultiExcept.hs view
@@ -10,9 +10,12 @@ module Control.Applicative.MultiExcept ( MultiExcept , fromEither+ , fromEitherPoly+ , join , runMultiExcept , succeed , throwError+ , throwErrors ) where import Data.Functor.Alt@@ -20,36 +23,52 @@ import qualified Data.DList.DNonEmpty as DNE import Data.List.NonEmpty (NonEmpty) --- | A MultiExcept is a success value, or one or more errors+-- | A 'MultiExcept' is a success value, or one or more errors. data MultiExcept err a = Success a | Errors (DNonEmpty err) deriving (Eq, Ord, Read, Show) --- | Run the computation+-- | Run the computation. runMultiExcept :: MultiExcept err a -> Either (NonEmpty err) a runMultiExcept (Errors errs) = Left $ DNE.toNonEmpty errs runMultiExcept (Success a) = Right a --- | Throw a single error+-- | Throw a single error. throwError :: err -> MultiExcept err a throwError = Errors . pure --- | Embeds a value into a MultiExcept context+-- | Throw one or more errors.+throwErrors :: DNonEmpty err -> MultiExcept err a+throwErrors = Errors++-- | Embeds a value into a 'MultiExcept' context. succeed :: a -> MultiExcept err a succeed a = Success a --- | Convert an Either to a MultiExcept+-- | Convert an 'Either' to a 'MultiExcept'. fromEither :: Either err a -> MultiExcept err a-fromEither (Left err) = Errors (DNE.singleton err)+fromEither (Left err) = throwError err fromEither (Right a) = Success a +-- | Convert a multi-error 'Either' to a 'MultiExcept'.+fromEitherPoly :: Either (DNonEmpty err) a -> MultiExcept err a+fromEitherPoly (Left errs) = Errors errs+fromEitherPoly (Right a) = Success a++-- | 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 '>>='.+join :: MultiExcept err (MultiExcept err a) -> MultiExcept err a+join (Success a) = a+join (Errors a) = Errors a+ instance Functor (MultiExcept err) where fmap f (Success a) = Success $ f a fmap _ (Errors errs) = Errors errs instance Applicative (MultiExcept err) where- pure = succeed+ pure = Success Errors l <*> Errors l' = Errors $ l <> l' Success f <*> Success a = Success $ f a
multi-except.cabal view
@@ -1,7 +1,7 @@ cabal-version: >=1.10 name: multi-except-version: 0.1.3.0+version: 0.1.4.0 synopsis: Multiple Exceptions description: Exception type that supports reporting multiple exceptions license: MIT