Skip to content

Instantly share code, notes, and snippets.

@dmyersturnbull
Created March 21, 2016 20:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dmyersturnbull/2295d91ef503bb3eec6d to your computer and use it in GitHub Desktop.
Save dmyersturnbull/2295d91ef503bb3eec6d to your computer and use it in GitHub Desktop.
Unordered pair in Scala
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
}
@jakequist
Copy link

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment