Created
March 21, 2016 20:29
-
-
Save dmyersturnbull/2295d91ef503bb3eec6d to your computer and use it in GitHub Desktop.
Unordered pair in Scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
case class UnorderedPair[A](a: A, b: A) { | |
override def equals(o: Any) = o match { | |
case that: UnorderedPair[A] => that.a == a && that.b == b || that.a == b && that.b == a | |
case _ => false | |
} | |
override def hashCode = a.hashCode * b.hashCode // commutative and unique | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks!