What do I need to do to compare two Java UUIDs? Do I need to create an instance of the Equal typeclass for java.util.UUID
?
CodePudding user response:
I assume you want to compare whether two UUIDs have the same value rather than the object references, in which case, the following suffices:
import scalaz._
import Scalaz._
import java.util.UUID
object UUIDEqualExample extends App {
val a = new UUID(12345678, 87654321)
val b = new UUID(12345678, 87654321)
val c = new UUID(11111111, 22222222)
implicit val eq: Equal[UUID] = Equal.equalA[UUID]
println(a === b) // true
println(a === c) // false
}