我想转换List[Either[String, Int]]Either[String, List[Int]]的列表。为此,我想使用Cats.sequence:

/* for ammonite users
interp.load.ivy("org.typelevel" %% "cats-core" % "1.0.1")

@
*/

import cats.instances.list._
import cats.instances.either._
import cats.syntax.traverse._

val seqCorrect: List[Either[String, Int]] = List(Right(1), Right(2), Right(3))

val result1 = seqCorrect.sequence

但是我有以下错误:
Cannot prove that Either[String,Int] <:< G[A].
val result1 = seqCorrect.sequence
                         ^

我发现错误消息非常无用。我该如何解决这个问题?

最佳答案

我认为您可能尚未启用partial-unification。最简单的方法是添加sbt-partial-unification plugin

如果您使用的是Scala 2.11.9或更高版本,则还可以简单地添加编译器标志:

scalacOptions += "-Ypartial-unification"

关于scala - 在ith列表上应用时出现cats.sequence错误,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/49978898/

10-11 10:27