Created
January 16, 2013 22:39
-
-
Save raronson/4551632 to your computer and use it in GitHub Desktop.
ordering of sets
This file contains hidden or 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
implicit def Set2OrderingSet[A : Ordering]: Ordering[Set[A]] = { | |
new Ordering[Set[A]] { | |
def compare(s1: Set[A], s2: Set[A]): Int = { | |
for((x,y) <- s1.toList.sorted zip s2.toList.sorted) { | |
val c = implicitly[Ordering[A]].compare(x, y) | |
if(c != 0) return c | |
} | |
return s1.size - s2.size | |
} | |
} | |
} |
tonymorris
commented
Jan 16, 2013
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment