I'm trying to combine Twitter Future with Cats Kleisli and Arrow and I have a compilation error that I don't know how to solve it.
The code is the following:
package com.example
import scala.language.higherKinds
import cats.arrow.Arrow
import cats.implicits._
import cats.data.{EitherT, Kleisli}
import com.twitter.util.Future
object ArrowApp extends App {
type Resp[A] = EitherT[Future, Exception, A]
type KleisliResp[A] = Kleisli[Resp, List[Int], A]
val first: KleisliResp[Int] = Kleisli(_ => EitherT[Future, Exception, Int](Future.value(Right(1))))
val second: KleisliResp[String] = Kleisli(_ => EitherT[Future, Exception, String](Future.value(Right("TEST"))))
def combine[F[_, _] : Arrow, A, B, C](fab: F[A, B], fac: F[A, C]): F[A, (B, C)] = Arrow[F].lift((a: A) => (a, a)) >>> (fab *** fac)
val firstAndSecond: KleisliResp[(Int, String)] = combine(first, second)
}
The error that I get it is:
Error:(20, 31) could not find implicit value for evidence parameter of type cats.arrow.Arrow[[A, B]cats.data.Kleisli[com.example.cats.ArrowApp.Resp,A,B]]
val firstAndSecond: KleisliResp[(Int, String)] = combine(first, second)
If I replace the Twitter Future with Scala Future and I import the global executor import scala.concurrent.ExecutionContext.Implicits.global then code runs.
My build.sbt looks like:
organization := "com.example"
name := "scala-test"
version := "1.0"
scalaVersion := "2.12.3"
libraryDependencies ++= Seq(
"org.typelevel" %% "cats-core" % "1.2.0",
"org.typelevel" %% "cats-free" % "1.2.0",
"org.scala-lang.modules" %% "scala-parser-combinators" % "1.1.0",
"com.twitter" %% "finagle-core" % "18.3.0"
)
scalacOptions ++= Seq("-Ypartial-unification")
resolvers += Resolver.sonatypeRepo("releases")
addCompilerPlugin("org.spire-math" %% "kind-projector" % "0.9.7")
Do you have any idea how to fix the compilation error?
Kind regards!
You probably need something like catbird, because it
[...] provides cats type class instances (and other useful cats-related stuff) for various Twitter Open Source Scala projects.
It currently includes the following:
- Type class instances for Future, Var, and Try (including Monad or MonadError, Semigroup, and equality)
Twitter's Future
has nothing to do with scala's standard Future
, and Cats does not provide any typeclasses for Twitter Future
s by default.