Combining futures of different types using cats
I have different types of futures.
import cats.Cartesian
import cats.instances.future._
import cats.syntax.cartesian._
import scala.concurrent.Future
import cats.implicits._
val aF : Future[Either[X, Y]] = getFuture(...)
val bF : Future[Either[X, Y]] = getFuture(...)
val cF = Future[List[Long]] = getFuture2(...)
val combinedFuture = Cartesian.tuple3(aF, bF, cF)
combinedFuture match {case (a, b, c) =>
...
}
But I am getting the error
Error:(36, 44) could not find implicit value for parameter cartesian: cats.Cartesian[scala.concurrent.Future]
val combinedFuture = Cartesian.tuple3(aF, bF, cF)
But as you can see I imported all implicits, intances.future._ and syntax.
I am using Cats 0.9.0 on Scala 2.11.8
+3
source to share
1 answer
You are missing the implicit ExecutionContext
:
import scala.concurrent.ExecutionContext.Implicits.global
I've had this happen many times when using a template like type in Future[T]
, it's always an execution context that is easily forgotten, but makes the type class not properly resolved by implicits.
+3
source to share