Is there a uniform method to perform equality with type checking? Unfortunately
val objectA:String = "test"
val objectB:Int = 2
objectA == objectB
the equality operator == doesn't complain if objectB is a Int while objectA is a String. I would need an operator like === that perform type checking as well (and I hope it is uniform to all scala obj). Does such operator exist?
You need to look at scalaz's === for type-safe equals - it's implemented as type class there.
You can also watch talk by Heiko Seeberger, where he describes how it's implemented:
http://days2011.scala-lang.org/node/138/275
You can also find some examples here:
http://scalaz.github.com/scalaz/scalaz-2.9.1-6.0.4/doc.sxr/scalaz/example/ExampleEqual.scala.html#24187
(in the examples they are using ≟
method, but it's simply alias for ===
)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With