0

I have this code:

 (for {
      oldResult <- EitherT[Future, A, B](getById(id))
      newResult <- EitherT.right(update(changeOldData(oldResult)))
    } yield newResult).value

Where the functions returns

 getById       -> Future[Either[A, B]]
 update        -> Future[B]
 changeOldData -> B

The entire block is suppose to return:

Future[Either[A, B]]

In IntelliJ, there is no complains about the code above, but when compiling, I'm getting the following error:

[error]  found   : B => cats.data.EitherT[scala.concurrent.Future,Nothing,B]
[error]  required: B => cats.data.EitherT[scala.concurrent.Future,A,B]
[error]           oldResult <- EitherT[Future, A, B](

I tried to not include the type and I'm getting the same error as well. Any idea why?

joao.sauer
  • 211
  • 2
  • 15
  • It's important to note that IntelliJ's presentation compiler for Scala does not have full functionality. So never rely on int. – Markus Appel Jan 29 '20 at 13:00

1 Answers1

2

When you call EitherT.right(..) the compiler cannot figure out what the left type of your either should be. That's why the error message says it found Nothing instead of A. You need to help it out a bit.

EitherT.right[A](update(changeOldData(oldResult)))

This will compile.

Saskia
  • 1,046
  • 1
  • 7
  • 23
  • Thanks, this fixed the issue. The funny part is that the error related to the first part of the For and not the second one. – joao.sauer Jan 29 '20 at 13:37