0

Trying to understand a way to do this without noisy explicit typing.

If I do the following:


// here maybeUser is Either[ServiceError, User]
// cacheService.remove(user) returns EitherT[Future, ServiceError, Unit]

def blah(): EitherT[Future, ServiceError, Unit] = {
    for {
      user <- EitherT.fromEither(maybeUser)
      _    <- cacheService
               .remove(user)
    } yield ()
}

This will return the following error:

diverging implicit expansion for type cats.kernel.Order[A]
[error] starting with value catsKernelStdOrderForFiniteDuration in trait FiniteDurationInstances
[error]       user <- EitherT.fromEither(maybeUser)

If I explicitly (noisy) type this, it works:

def blah(): EitherT[Future, ServiceError, Unit] = {
    for {
      user <- EitherT.fromEither(maybeUser):EitherT[Future, ServiceError, User]
      _    <- cacheService
               .remove(maybeUser)
    } yield ()
}

But explicitly typing becomes tiresome after awhile, especially in other (larger) parts of the code. Any ideas?

mat4nier
  • 262
  • 4
  • 14
  • 3
    What does `EitherT.fromEither[Future](maybeUser)` say? Also, [this answer](https://stackoverflow.com/questions/52086992/scala-how-to-combine-eithert-with-either-in-for-comprehension) shows the shorter syntax. – Andrey Tyukin Aug 09 '19 at 16:51
  • 1
    Facepalm. This works and is totally obvious. Apologies for the duplicated question. – mat4nier Aug 09 '19 at 17:00

0 Answers0