I've to deal with an immutable object in scala 2.7.5, and one of its member is an immutable Sortedset. I've no problem with addition, to synthetise, it gives:
class MyClass[A](s:SortedSet[A]) {
...
def + (elem:A):MyClass[A] {
new MyClass(s + elem)
}
}
And it works, since + operator is overload in trait sortedSet to return a SortedSet.
Unfortunately removing an element fails since - methos is not overloaded:
class MyClass[A](s:SortedSet[A]) {
...
def - (elem:A):MyClass[A] {
new MyClass(s - elem) // Compiler error: (s - elem) is a Set[A]
}
}
Does anyone knows how I can obtain a sorted set when i suppress an element knowing that: - I don't want to use a more specific kind of set like TreeSet. - I can't use a less specific trait as Set[A] instead of my SortedSet.