Scala 符号';输入cats.MonadFilter';类路径中缺少

Scala 符号';输入cats.MonadFilter';类路径中缺少,scala,scala-cats,monix,Scala,Scala Cats,Monix,我正在阅读本教程 基于此,我将依赖项定义为 object Dependencies { lazy val scalaTest = "org.scalatest" %% "scalatest" % "3.0.5" lazy val cats = "org.typelevel" %% "cats-core" % "1.2.0" lazy val monix = "io.monix" %% "monix" % "2.3.3" lazy val monixCats = "io.monix

我正在阅读本教程

基于此,我将依赖项定义为

object Dependencies {
  lazy val scalaTest = "org.scalatest" %% "scalatest" % "3.0.5"
  lazy val cats = "org.typelevel" %% "cats-core" % "1.2.0"
  lazy val monix = "io.monix" %% "monix" % "2.3.3"
  lazy val monixCats = "io.monix" %% "monix-cats" % "2.3.3"
}
下面是我的代码

// future
import scala.concurrent.ExecutionContext.Implicits.global
import scala.concurrent._
import scala.concurrent.duration._

// cats
import cats.Monad
import cats.implicits._

// monix
import monix.eval.Task
import monix.cats._
import monix.cats.reverse._


trait ProductRepository[M[_]] {
  def findProduct(productId: ProductId) : M[Option[Product]]
  def saveProduct(product: Product) : M[Unit]
  def incrementProductSales(productId: ProductId, quantity: Long) : M[Unit]
}

class ProductRepositoryWithFuture extends ProductRepository[Future] {
  def findProduct(productId: ProductId) : Future[Option[Product]] = {
    Future.successful(Some(Product(productId, "foo")))
  }
  def saveProduct(product: Product) : Future[Unit] = {
    Future.successful()
  }
  def incrementProductSales(productId: ProductId, quanity: Long) : Future[Unit] = {
    Future.successful()
  }
}

class ProductRepositoryWithTask extends ProductRepository[Task] {
  def findProduct(productId: ProductId) : Task[Option[Product]] = {
    Task.now(Some(Product(productId, "foo")))
  }
  def saveProduct(product: Product) : Task[Unit] = {
    Task.unit
  }
  def incrementProductSales(productId: ProductId, quantity: Long) : Task[Unit] = {
    Task.unit
  }
}
但是我犯了很多错误。似乎我使用的猫的版本与Monix使用的版本不兼容

我还试图删除我对猫的依赖,只是导入了monix,这样monix就引入了自己版本的猫。但即使这样也无法编译

error] /Users/foobar/code/tagless/src/main/scala/example/Hello.scala:54:24: Symbol 'type cats.MonadFilter' is missing fromthe classpath.
[error] This symbol is required by 'method monix.cats.MonixToCatsCore7.monixToCatsMonadFilter'.
[error] Make sure that type MonadFilter is in your classpath and check for conflicting dependencies with `-Ylog-classpath`.
[error] A full rebuild may help if 'MonixToCatsCore7.class' was compiled against an incompatible version of cats.
[error]       repo.findProduct(id).flatMap{
[error]                        ^
[error] /Users/foobar/code/tagless/src/main/scala/example/Hello.scala:54:23: diverging implicit expansion for type monix.types.Comonad[M]
[error] starting with method catsToMonixComonad in trait CatsCoreToMonix5
[error]       repo.findProduct(id).flatMap{
[error]                       ^
[error] /Users/foobar/code/tagless/src/main/scala/example/Hello.scala:54:28: value flatMap is not a member of type parameter M[Option[example.Application.Product]]
[error]       repo.findProduct(id).flatMap{
[error]                            ^
[error] /Users/foobar/code/tagless/src/main/scala/example/Hello.scala:56:30: value copy is not a member of Any
[error]           val newProduct = p.copy(name = name)
[error]                              ^
[error] /Users/foobar/code/tagless/src/main/scala/example/Hello.scala:56:40: reassignment to val
[error]           val newProduct = p.copy(name = name)
[error]                                        ^
[error] /Users/foobar/code/tagless/src/main/scala/example/Hello.scala:57:27: diverging implicit expansion for type monix.types.MonadError[M,E]
[error] starting with method catsToMonixMonadError in trait CatsCoreToMonix3
[error]           repo.saveProduct(newProduct).map(_ => Some(p))
[error]                           ^
[error] /Users/foobar/code/tagless/src/main/scala/example/Hello.scala:57:40: value map is not a member of type parameter M[Unit]
[error]           repo.saveProduct(newProduct).map(_ => Some(p))
[error]                                        ^
[error] /Users/foobar/code/tagless/src/main/scala/example/Hello.scala:59:16: diverging implicit expansion for type cats.Comonad[M]
[error] starting with method monixToCatsComonad in trait MonixToCatsCore5
[error]           Monad[M].pure(None)
[error]                ^
[error] 8 errors found

这些错误是由依赖项之间的不兼容引起的。 例如,当您试图使用二进制不兼容的
1.2.0
时,monix
2.3.3
依赖于CAT
0.9.0

您应该尝试将
monix
升级到
3.x
或将
cats
降级到
0.9.0


另外,从cats
0.9.0
1.x
的转换有很多缺点,您必须确保您使用的所有库都是针对相同(或至少二进制兼容)版本的cats编译的。

这些错误是由依赖项之间的不兼容引起的。 例如,当您试图使用二进制不兼容的
1.2.0
时,monix
2.3.3
依赖于CAT
0.9.0

您应该尝试将
monix
升级到
3.x
或将
cats
降级到
0.9.0


另外,从cats
0.9.0
1.x
的转换有很多缺点,您必须确保您使用的所有库都是针对相同(或至少二进制兼容)版本的cats编译的。

完整代码。以防万一,如果有人需要的话。我在您的依赖项集上看到了类似的错误,如果我升级到这些依赖项,我会通过:libraryDependencies+=“io.monix”%%“monix”%%“3.0.0-RC1”和libraryDependencies+=“org.typelevel”%%“cats core”%%“1.2.0”。但我很好奇如何才能让它在版本2中工作,所以我会继续寻找。谢谢。我试过了,但根本无法修复。完整代码。以防万一,如果有人需要的话。我在您的依赖项集上看到了类似的错误,如果我升级到这些依赖项,我会通过:libraryDependencies+=“io.monix”%%“monix”%%“3.0.0-RC1”和libraryDependencies+=“org.typelevel”%%“cats core”%%“1.2.0”。但我很好奇如何才能让它在版本2中工作,所以我会继续寻找。谢谢。我试过了,但根本没法修好。