title: Override toString in a Scala set
body: <p>I want to create a set of integers called <code>IntSet</code>. <code>IntSet</code> is identical to <code>Set[Int]</code> in every way except that its <code>toString</code> function prints the elements as comma-delimited (the same as if you called <code>mkString(",")</code>), and it has a constructor that takes a <code>Traversable</code> of integers. What is the simplest way to do this?</p>
  
  <pre><code>&gt; IntSet((1 to 3)).toString
  1,2,3
  </code></pre>
  
  <p>I'd think there would be some one-line way to do this, but I've been fiddling around with implicit functions and extending <code>HashSet</code> and I can't figure it out.</p>
  
  <hr>
  
  <p>The trick is to use a proxy object. <a href="https://stackoverflow.com/users/172677/eastsun">Eastsun</a> has the answer below. Here's a slightly different version that defines a named <code>IntSet</code> type and makes it immutable.</p>
  
  <pre><code>import collection.immutable.{HashSet, SetProxy}
  
  class IntSet(values: Traversable[Int]) extends SetProxy[Int] {
    override val self: Set[Int] = HashSet(values.toSeq:_*)
    override def toString() = mkString(",")
  }
  </code></pre>