Created

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist

Inject Either into a MaybeT (Writer e)

View CollectLeft2.hs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
import Data.Monoid
import Control.Monad
import Control.Applicative
import Control.Error
import Control.Monad.Trans.Class
import Control.Monad.Trans.Writer
 
collectEither :: (Monoid (es a), Applicative es) => Either a b -> MaybeT (Writer (es a)) b
collectEither (Left e) = lift (tell (pure e)) >> mzero
collectEither (Right a) = return a
 
runCollectLeft :: MaybeT (Writer es) b -> Either es b
runCollectLeft maybeWriter =
case runWriter (runMaybeT maybeWriter) of
(Just x, _) -> Right x
(Nothing, es) -> Left es
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.