LoginSignup
1
1

More than 3 years have passed since last update.

カリー化されたcase classは2つ目以降の引数グループの値を等価チェックに使わない

Last updated at Posted at 2020-11-05

動作確認コード

import org.scalatest.matchers.should.Matchers
import org.scalatest.wordspec.AnyWordSpec

class CaseClassEqualityTest extends AnyWordSpec with Matchers {
  case class Class1(val1: String)(implicit val val2: Int)
  case class Class2(val1: String)(implicit val2: Int)
  case class Class3(val1: String)(val2: Int)

  "カリー化されたcase class" should {
    "2つ目以降のカッコの値を等価チェックに使わない" in {
      Class1("1")(2) should be(Class1("1")(2))
      Class1("1")(2) should not be (Class1("aaa")(2))
      Class1("1")(2) should be(Class1("1")(999999))

      Class2("1")(2) should be(Class2("1")(2))
      Class2("1")(2) should not be (Class2("aaa")(2))
      Class2("1")(2) should be(Class2("1")(999999))

      Class3("1")(2) should be(Class3("1")(2))
      Class3("1")(2) should not be (Class3("aaa")(2))
      Class3("1")(2) should be(Class3("1")(999999))
    }
  }
}

scala-sandbox/CaseClassEqualityTest.scala at bdf74c0f5d3b06c58c34b2e1068163fb2e319a50 · tksugimoto/scala-sandbox

関連

All the functionality of case classes only apply to the first constructor arguments group. AFAIK, that is the intended behaviour.

ケースクラスのすべての機能は、最初のコンストラクター引数グループにのみ適用されます。私の知る限りでは、それは意図された振る舞いです。

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1