推特未来与猫箭
Twitter Future & Cats Arrow
我正在尝试将 Twitter Future 与 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)
如果我用 Scala Future 替换 Twitter 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")
你知道如何修复编译错误吗?
亲切的问候!
您可能需要 catbird 之类的东西,因为它
[...] 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 的 Future
与 scala 的标准 Future
无关,Cats 默认不为 Twitter Future
提供任何类型类。
我正在尝试将 Twitter Future 与 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)
如果我用 Scala Future 替换 Twitter 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")
你知道如何修复编译错误吗?
亲切的问候!
您可能需要 catbird 之类的东西,因为它
[...] 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 的 Future
与 scala 的标准 Future
无关,Cats 默认不为 Twitter Future
提供任何类型类。