I’d think the best you could do is to come up with an Enumerable
type class and implement this directly for the types of interest.
You could go with some macro based or reflection based approach for sealed traits with object children and somehow integrate this with the type class. You might even succeed extending this to case class children with Enumerable
members, but this almost certainly will already require more of your life time than you’re willing to devote. And even then, you’d only have covered a very limited set of special cases. Most types will have an infinite domain, anyway, and of the few remaining types, the domain size will still exceed available memory.
In short, don’t go there. As @tarsa put it: Pandora’s box, whatever approach you choose.