concrete functor and monad transformers
#35Add Errors utility functions
Hi Ross,
I occasionally use Errors
to accumulate unrelated errors in an Either
-heavy program (where the Monad is required). It feels like hoistErrors
is missing from the API; it would be nice to use a type like this without learning about the internals of Lift
and Constant
.
Curious of your opinions on including this in Control.Applicative.Lift
.
I also include sequenceErrors
for your consideration; this has been the most useful application of Errors
for me.
hoistErrors :: Either e a -> Errors e a
hoistErrors e =
case e of
Left es ->
Other (Constant es)
Right a ->
Pure a
-- | Like 'sequence', but accumulating all errors in case of a 'Left'.
sequenceErrors :: (Monoid e, Traversable f) => f (Either e a) -> Either e (f a)
sequenceErrors =
runErrors . traverse hoistErrors
Thanks for maintaining transformers
! I use it every day.
- Tim
- description updated
added the first one as eitherToErrors. Maybe the other is to minor to add
- status set to closed