kostja kostja - 8 months ago 119
Scala Question

missing Cats Functor[Future] instance

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)[http://typelevel.org/cats/typeclasses/functor.html]

What am I missing here?

Thank you

Answer Source

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._

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.