missing Cats Functor[Future] instance

kostja picture kostja · Apr 13, 2017 · Viewed 8.6k times · Source

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

Answer

Federico Pellegatta picture Federico Pellegatta · Apr 13, 2017

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.