I am trying to use OptionT
to combine methods returning Future[Option[T]]
in a for-comprehension.
import cats.data._ import cats.implicits._ import cats.instances.future._ for { data <- OptionT(repo.getData(id)) ... }
The compiler error I am getting:
could not find implicit value for parameter F cats.Functor[scala.concurrent.Future]
This recent example suggests that this is (was?) possible.
so do the docs in the pull request for adding OptionT
and the cats Functor
docs
What am I missing here?
Thank you
Following imports work for me (also mentioned in approved answer),
import cats.data.OptionT import cats.instances.future._ // or import cats.implicits._ // as implicits include FutureInstances import scala.concurrent.Future import scala.concurrent.ExecutionContext.Implicits.global
Also, the important thing was the dependencies as I was using org.typelevel:cats:0.9.0
along with cats-core-1.1.0
which was causing Symbol 'type cats.kernel.instances.EqInstances' is missing from the classpath.
Had to remove older cats-0.9.0
and use latest cats-core
and cats-kernel
.
libraryDependencies ++= Seq( "org.typelevel" %% "cats-core" % "1.1.0", "org.typelevel" %% "cats-kernel" % "1.2.0", "org.scalatest" %% "scalatest" % "3.0.4" % Test )
By importing cats.implicits._
you are actually already importing cats.syntax.AllSyntax
and cats.instances.AllInstances
Try using just those imports:
import cats.data._ import cats.implicits._
or (according to your needs):
import cats.data._ import cats.instances.future._
or more specifically:
import cats.data._ import cats.instances.future.catsStdInstancesForFuture
you may also need:
import scala.concurrent.Future import scala.concurrent.ExecutionContext.Implicits.global
Note: of course you have to implicitly provide an actual ExecutionContext
in a production environment.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With