Twitter未来与猫之箭

时间:2018-08-12 11:50:24

标签: scala scala-cats twitter-finagle cats-effect

我正在尝试将 Twitter未来 Cats Kleisli和Arrow 结合起来,但出现编译错误,我不知道如何解决。

代码如下:

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)
}

我得到的错误是:

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)

如果将 Twitter Future 替换为 Scala Future ,然后导入全局执行程序 import scala.concurrent.ExecutionContext.Implicits.global ,代码运行。

我的 build.sbt 如下:

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")

您知道如何解决编译错误吗?

亲切的问候!

1 个答案:

答案 0 :(得分:3)

您可能需要catbird之类的东西,因为它

  

[...]为各种Twitter开源Scala项目提供了cats类型的类实例(以及其他与cats相关的有用的东西)。

     

当前包括以下内容:

     
      
  • 为Future,Var和Try(包括Monad或MonadError,Semigroup和等式)键入类实例
  •   

Twitter的Future与scala的标准Future无关,并且Cats默认不为Twitter Future提供任何类型类。