title: How can I define a custom equality operation that will be used by immutable Set comparison methods
body: <p>I have an immutable Set of a class, Set[MyClass], and I want to use the Set methods intersect and diff, but I want them to test for equality using my custom equals method, rather than default object equality test</p>
  
  <p>I have tried overriding the == operator, but it isn't being used.</p>
  
  <p>Thanks in advance.</p>
  
  <p>Edit:</p>
  
  <p>The intersect method is a concrete value member of GenSetLike</p>
  
  <p>spec: <a href="http://www.scala-lang.org/api/current/scala/collection/GenSetLike.html" rel="noreferrer">http://www.scala-lang.org/api/current/scala/collection/GenSetLike.html</a>
  src: <a href="https://lampsvn.epfl.ch/trac/scala/browser/scala/tags/R_2_9_1_final/src//library/scala/collection/GenSetLike.scala#L1" rel="noreferrer">https://lampsvn.epfl.ch/trac/scala/browser/scala/tags/R_2_9_1_final/src//library/scala/collection/GenSetLike.scala#L1</a></p>
  
  <pre><code>def intersect(that: GenSet[A]): Repr = this filter that
  </code></pre>
  
  <p>so the intersection is done using the filter method.</p>
  
  <p>Yet another Edit:</p>
  
  <p>filter is defined in TraversableLike</p>
  
  <p>spec: <a href="http://www.scala-lang.org/api/current/scala/collection/TraversableLike.html" rel="noreferrer">http://www.scala-lang.org/api/current/scala/collection/TraversableLike.html</a></p>
  
  <p>src: <a href="https://lampsvn.epfl.ch/trac/scala/browser/scala/tags/R_2_9_1_final/src//library/scala/collection/TraversableLike.scala#L1" rel="noreferrer">https://lampsvn.epfl.ch/trac/scala/browser/scala/tags/R_2_9_1_final/src//library/scala/collection/TraversableLike.scala#L1</a></p>
  
  <pre><code>def filter(p: A =&gt; Boolean): Repr = {
    val b = newBuilder
        for (x &lt;- this) 
          if (p(x)) b += x
        b.result
  }
  </code></pre>
  
  <p>What's unclear to me is what it uses when invoked without a predicate, p. That's not an implicit parameter.</p>