scala.collection.immutable

trait SetProxy

[source: scala/collection/immutable/SetProxy.scala]

trait SetProxy[A]
extends Set[A] with SetProxyTemplate[A, Set[A]]

This is a simple wrapper class for scala.collection.immutable.Set.

It is most useful for assembling customized set abstractions dynamically using object composition and forwarding.

Method Summary
override def + (elem : A) : SetProxy[A]
Creates a new set with an additional element, unless the element is already present.
override def - (elem : A) : SetProxy[A]
Creates a new set with given element removed from this set, unless the element is not present.
override def empty : SetProxy[A]
override def thisCollection : SetProxy[A]
Methods inherited from SetProxyTemplate
contains, isEmpty, apply, intersect, &, union, |, diff, &~, subsetOf
Methods inherited from IterableProxyTemplate
iterator, foreach, foldRight, reduceRight, toIterable, head, takeRight, dropRight, sameElements, toStream, view, view
Methods inherited from TraversableProxyTemplate
self (abstract), nonEmpty, size, hasDefiniteSize, ++, ++, map, flatMap, filter, filterNot, remove, partition, groupBy, forall, exists, count, find, foldLeft, /:, :\, reduceLeft, reduceLeftOption, reduceRightOption, headOption, tail, last, lastOption, init, take, drop, slice, takeWhile, dropWhile, span, splitAt, copyToBuffer, copyToArray, copyToArray, toArray, toList, toSequence, toSet, mkString, mkString, mkString, addString, addString, addString, stringPrefix
Methods inherited from Proxy
hashCode, equals, toString
Methods inherited from Set
companion
Methods inherited from SetTemplate
newBuilder, **
Methods inherited from Subtractable
-, --, --
Methods inherited from Addable
+, ++, ++
Methods inherited from Function1
compose, andThen
Methods inherited from IterableTemplate
elements, first, firstOption, toSeq, projection
Methods inherited from TraversableClass
genericBuilder, unzip, flatten, transpose
Methods inherited from TraversableTemplate
filterMap
Methods inherited from AnyRef
getClass, clone, notify, notifyAll, wait, wait, wait, finalize, ==, !=, eq, ne, synchronized
Methods inherited from Any
==, !=, isInstanceOf, asInstanceOf
Method Details
override def thisCollection : SetProxy[A]

The proper way to do this would be to make self of type This. But unfortunately this makes this to be of type Traversable[A]. Since Traversable is a subtype of TraversableTemplate, all methods of this are taken from Traversable. In particular the newBuilder method is taken from Traversable, which means it yields a Traversable[A] instead of a This.

The right way out of this is to change Scala's member selection rules, so that always the most specific type will be selected, no matter whether a member is abstract or concrete. I tried to fake this by having a method thisTemplate which returns this at the Template type. But unfortunately that does not work, because we need to call newBuilder on this at the Template type (so that we get back a This) and newBuilder has to be a protected[this] because of variance.
The less appealing alternative is implemented now: Forget the self type and introduce a thisCollection which is this seen as an instance of This. We should go back to this once we have ameliorated Scala's member selection rules.


override def empty : SetProxy[A]

override def +(elem : A) : SetProxy[A]
Creates a new set with an additional element, unless the element is already present.
Parameters
elem - the element to be added

override def -(elem : A) : SetProxy[A]
Creates a new set with given element removed from this set, unless the element is not present.
Parameters
elem - the element to be removed