I think #1644 is related.
Basicly something like:
import cats.implicits._
import cats.data.EitherT
import cats.MonadError
def fromMonadError[F[_], A, B](me: F[B])(implicit ev: MonadError[F, A]) = {
EitherT(me.map(Either.right[A, B]).recover{case ex => Either.left[A, B](ex)})
}
Or if we have this functionality already maybe it would worth a mention in the EitherT/MonadError documentation.
If others think this is useful, I try to PR it :)
I think this is neat, though I believe it could be more simply implemented with attempt. Something like this:
def fromMonadError[F[_], E, A](fa: F[A])(implicit F: MonadError[F, E]): EitherT[F, E, A] =
EitherT(F.attempt(fa))
It's kind of like a mechanism for lifting into a redundant signal channel. I do stuff like this semi-frequently; I'm curious if others do as well.
It comes up surprisingly often for me as well.
It seems this already exists and is called attemptT.
Nice! So can we add this to the EitherT docs?
Most helpful comment
It seems this already exists and is called
attemptT.