Scala: Ignore case class field for equals/hascode?
class, pattern-matching, scala
Solution
Only parameters in the first parameter section are considered for equality and hashing.
scala> case class Foo(a: Int)(b: Int)
defined class Foo
scala> Foo(0)(0) == Foo(0)(1)
res0: Boolean = true
scala> Seq(0, 1).map(Foo(0)(_).hashCode)
res1: Seq[Int] = List(-1669410282, -1669410282)
UPDATE
To expose `b` as a field:
scala> case class Foo(a: Int)(val b: Int)
defined class Foo
scala> Foo(0)(1).b
res3: Int = 1
Problem
Is it possible to ignore a field of a case class in the equals/haschode method of the case class? My use case is that I have a field that is essentially metadata for rest of the data in the class.