EitherT -package:ghc-lib-parser
Not on Stackage, so not searched.
EitherT monad transformer
Map over both arguments at the same time.
Specialised version of
bimap for
EitherT.
Given an
Either, convert it to a
Maybe, where
Left becomes
Nothing.
\x -> eitherToMaybe (Left x) == Nothing
\x -> eitherToMaybe (Right x) == Just x
Generalize
Either e as
MonadError e m.
If the argument has form
Left e, an error is produced in the
monad via
throwError. Otherwise, the
Right a part is
forwarded.
Takes an either and transforms it into something of the more generic
MonadError class.
Encode
Either into a generalised sum type.
Transform an
Either into a
Validation.
>>> eitherToValidation (Right "whoop")
Success "whoop"
>>> eitherToValidation (Left "nahh")
Failure "nahh"
This function can be used to implement
tryFrom with a function
that returns
Either. For example:
-- Avoid this:
tryFrom s = case f s of
Left e -> Left . TryFromException s . Just $ toException e
Right t -> Right t
-- Prefer this:
tryFrom = eitherTryFrom f
Convert an
Either to a
Maybe.
A
Right value becomes
Just.
>>> eitherToMaybe $ Right 3
Just 3
A
Left value becomes
Nothing.
>>> eitherToMaybe $ Left "bye"
Nothing
Convert Either to Gauge, 0 meaning Right