Missing Cat Functor Instance [Future]

I am trying to use OptionT to combine methods that return Future[Option[T]] for understanding.

 import cats.data._ import cats.implicits._ import cats.instances.future._ for { data <- OptionT(repo.getData(id)) ... } 

I get a compiler error:

 could not find implicit value for parameter F cats.Functor[scala.concurrent.Future] 

This recent example suggests that it (was?) Possible.

same as documents in add request to add OptionT

and cats Functor documents

What am I missing here?

thanks

+13
scala future monad-transformers scala-cats
source share
2 answers

cats.implicits._ importing cats.implicits._ you are actually already importing cats.syntax.AllSyntax and cats.instances.AllInstances

Try using only these 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 must implicitly provide the actual ExecutionContext in the production environment.

+18
source share

The following import works for me (also mentioned in the 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 

In addition, dependencies were important since I used org.typelevel:cats:0.9.0 along with cats-core-1.1.0 that Symbol 'type cats.kernel.instances.EqInstances' is missing from the classpath. that Symbol 'type cats.kernel.instances.EqInstances' is missing from the classpath.

I had to remove the old cats-0.9.0 and use the latest cats-core cats-kernel and cats-core 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 ) 
0
source share

All Articles