【发布时间】:2018-07-20 09:36:20
【问题描述】:
我正在尝试为案例类实现 Eq,但我不断收到编译器错误。我很确定我错过了一些进口,但不确定是哪一个。这是我所做的:
import cats.Eq
import cats.syntax.eq._
final case class Cat(name: String, age: Int, color: String)
implicit val catEq: Eq[Cat] = Eq.instance[Cat] { (cat1, cat2) =>
cat1.name === cat2.name && cat1.age === cat2.age && cat1.color === cat2.color
}
我正在使用cats-core 1.0.1 库。以下是编译器所说的:
<console>:17: error: value === is not a member of String
cat1.name === cat2.name && cat1.age === cat2.age && cat1.color === cat2.color
^
<console>:17: error: value === is not a member of Int
cat1.name === cat2.name && cat1.age === cat2.age && cat1.color === cat2.color
^
<console>:17: error: value === is not a member of String
cat1.name === cat2.name && cat1.age === cat2.age && cat1.color === cat2.color
【问题讨论】:
标签: scala scala-cats