I have a *-parameter method. I would like to be able to pass a mix of atoms and groups
of atoms into the method. Ideally I would like the groups to be able to hold groups too.
The grammar rule would be:
X = (X | atom)*
The groups need to ordered, but not necessarily of class List.
The motivation is that there are many calls to the *-parameter method and some groups of parameters occur more than once amongst these calls. I would like to be able to store these groups in vals to re-use them.
Why not something like this?
If you’re looking for a more fancy way to do it using union types, try reading Miles Sabin’s amazing post on how to implement union types in Scala. This should probably not be your first choice, though, as a solution implementing a common trait like
GroupOrAtomis clearer and easier.