Skip to content

Instantly share code, notes, and snippets.

@mads-hartmann
Created September 12, 2012 12:27
Show Gist options
  • Save mads-hartmann/3706292 to your computer and use it in GitHub Desktop.
Save mads-hartmann/3706292 to your computer and use it in GitHub Desktop.
Specifying a custom equivalence relation for sets
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
@mads-hartmann
Copy link
Author

FYI: I ended up projecting out the property I wanted and added that to a set.

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