Created
September 12, 2012 12:27
-
-
Save mads-hartmann/3706292 to your computer and use it in GitHub Desktop.
Specifying a custom equivalence relation for sets
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 Person(name: String, age: Int) | |
val p1 = Person("Mads",22) | |
val p2 = Person("Mikkel",22) | |
implicit val eq: Equiv[Person] = new Equiv[Person] { | |
def equiv(x: Person, y: Person) = x.age == y.age | |
} | |
Set(p1,p2) // Set(Person(Mads,22), Person(Mikkel,22)) | |
Set(p1,p2)(eq) // should give Set(Person(Mads, 22)) but it doesn't work |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
FYI: I ended up projecting out the property I wanted and added that to a set.