title: Pattern matching in Scala with generic return type
body: <p>There are four different types: Location, Language, Technology and Industry. There is a repository for each type that can return a collection of these types. For example a list of Locations. Each type has a name property with type String. There is a list of Strings. which can contain names of Locations, Languages, etc. I would like to write a function to find those typed entities (Location, Language, ...) that match the names of the String list. I was thinking something about like this:</p>
  
  <pre><code>def find[T](names: String): Set[T] = {
    val collection = T match {
      case Language =&gt; LanguageRepository.getAll
      case Location =&gt; LocationRepository.getAll
      case Teehnology =&gt; TechnologyRepository.getAll
      case Industry =&gt; IndustryRepository.getAll
    }
    // find the elements in the collection
  }
  </code></pre>
  
  <p>This is not correct, so how can the querying of the collection be done, and after that how can I be sure that the name property is there?</p>