How to properly implement a custom extractor for case classes in Scala?
I'm trying to configure This might be a silly question, but I'm trying to create a custom extractor for a case class in Scala, but I'm running into issues when I try to match against nested case classes... My goal is to extract values from a complex structure in a clean way. Here's a simplified version of what I have: ```scala case class Address(city: String, postalCode: String) case class Person(name: String, address: Address) object PersonExtractor { def unapply(person: Person): Option[(String, String)] = { Some((person.name, person.address.city)) } } val john = Person("John Doe", Address("New York", "10001")) ``` When I try to use my extractor, I do it like this: ```scala john match { case PersonExtractor(name, city) => println(s"Name: $name, City: $city") case _ => println("No match") } ``` However, I'm working with an behavior that states `type mismatch; found: Person required: PersonExtractor.type`. It seems like the extractor isn't being recognized correctly. I read that I might need to explicitly define the extractor's return type, but I'm not sure how to do that effectively. I've also tried changing the extract method to return `None` when the match fails, but that hasn't resolved the scenario. Can someone provide insights on how to correctly implement a custom extractor for nested case classes? Are there any best practices I should be aware of? My Scala version is 2.13.6, and I'm using IntelliJ IDEA as my IDE for development. My development environment is Ubuntu. Am I missing something obvious? For context: I'm using Scala on Ubuntu 22.04. Could someone point me to the right documentation? The stack includes Scala and several other technologies. This issue appeared after updating to Scala 3.11. Am I approaching this the right way?