I’ve got a pattern match which works the same on an object when the object is at the top level or embedded within another class. The code that should be executed is the same for both cases.
I’ve tried to show an example of what I mean below where a string object is either top level or within an object of type A. Is this sort of thing possible (to reduce code duplication)? I ran it in Scastie but it says illegal variable in pattern alternative.
case class A(str: String) object main { val something: Any = "sfdsd" something match { case A(str: String) | str: String => println("hello") } }