If I’m doing lots of pattern matching against a (relatively) complex case class, but most of the time I’m only interested in one or two of its fields. Is there a way to abstract away the other fields (perhaps by wrapping the class?)? Here’s an example of the type of thing I’m trying to simplify:
def receive = {
case HttpRequest(POST, "foo", _, HttpBody(_, body), _) => // action
case HttpRequest(GET, "bar", _, _, _) => // action
}
I’m only ever really interested in the request type, url and sometimes body so I would ideally like to define a pattern match as case Request(POST, "foo", body) or similar.
Just make your own
Requestextractor. Here’s a simplified example: