Logo

Programming-Idioms

This language bar is your friend. Select your favorite languages!
  • Scala

Idiom #114 Test deep equality

Set boolean b to true if objects x and y contain the same values, recursively comparing all referenced elements in x and y.
Tell if the code correctly handles recursive types.

case class A(a: Int, b: Float, c: String)
val x = A(1,2.2f,"hello")
val y = A(1,2.2f,"hello")

b = x == y 
(def b (identical? x y))

for external entities, identical will check if references point to the same object

New implementation...
< >
programming-idioms.org