Really struggling to figure out extending the immutable Set with a class that will represent a Set of concrete type. I’m doing this to try and create a nice DSL.
I’d like to have a class Thing, and when you add ‘things’ together you get a ThingSet object, which extends Set.
class Thing(val name:String){
def +(other: Thing):ThingSet = new ThingSet() + other
}
I just can’t figure out how to make the ThingSet object. I know I need to mix in traits like GenericSetTemplate, SetLike etc. But I just can’t make it work.
Please, can anybody give me some pointers, as I can’t find anything explicit enough to learn from. I’ve tried looking at the BitSet and HashSet implementations, but get lost.
Adapting from this Daily Scala post as well as the source to
BitSet, which is a wonderful example here because it is not a parameterized collection, and is rather short and simple.