I´m doing an example using monad transformer EitherT of scalaZ with OptionT but I have a compilation error which I dont understand.
Here my example code
class EitherTMonadTransformer {
case class Error(msg: String)
case class User(username: String, email: String)
def authenticate(token: String): Future[Error \/ String] = Future {
\/.right("token")
}
def getUser(username: String): Future[Option[User]] = Future {
Some(User("paul", "[email protected]"))
}
val userObj: Future[\/[Error, Nothing]] =
(for {
username <- EitherT(authenticate("secret1234"))
user <- OptionT(getUser(username))
} yield user.username).run
@Test
def eitherTAndOptionT(): Unit = {
println(userObj)
}
}
The compilation error says
Error:(32, 12) type mismatch;
found : scalaz.OptionT[scala.concurrent.Future,String]
required: scalaz.EitherT[scala.concurrent.Future,EitherTMonadTransformer.this.Error,?]
user <- OptionT(getUser(username))
Any idea what´s wrong?
Regards.