Say you have an EitherT that looks something like this:
type StateListOfString[+T] = State[List[String], T]
type MyEitherT = EitherT[StateListOfString, Int, Boolean]
If you have a for-comprehension that could return a left:
my computation = for {
a <- thingThatCouldReturnLeft
b <- otherThingThatCouldReturnLeft
} yield b
How can you follow up with a for-comprehension that manipulates state before itself returning the left?
I think I want something very close to orElse, but orElse doesn't have access to the value of the left:
def orElse[AA >: A, BB >: B](x: => EitherT[F, AA, BB])(implicit F: Bind[F]): EitherT[F, AA, BB] = {
If it took something like (x: => Int => EitherT[F, AA, BB]) instead of just (x: => EitherT[F, AA, BB]), it would work.
I had tried starting with:
for {
a <- myComputation.isLeft
// OK, now I have something sensible, and I can follow up with something like
// a leftMap
But if I start by calling isLeft, it looks like the computation is run at least twice, once for the isLeft, and again when I call something like leftMap.
What's the right thing to use here?