FYI, it would be more idiomatic to discard the enclosing `if (s == document) { ` and just add the following guard to your pattern:

```scala
case Id(id, _) if s == selector =>
```