(Still new to scala) I have a List[SortedSet[A]]
, and I'd like a unique SortedSet[A]
with all (unique and sorted) elements. How should I do that?
My goal is: I have a class, say Container
, that contain a list of Element
and a list of (sub)Container
. This class should implement a recursive getSortedElements(): SortedSet[Element]
methods.
So I easily have this invalid code:
case class Container(myElements: List[Element], myContainers: List[Container]){
def getSortedElements(): SortedSet[Element] =
SortedSet(myElements) ++ SortedSet(myContainers.map(_.getSortedElements))
}