title: Efficiently mapping members to their owning structure
body: <p>Lets say I have the class <code>Family</code> which has a structure of members of the family inside it, not really relevant for this problem as long as there is a function provided by <code>Family</code> called <code>def member(m : Member) : Boolean</code> which returns <code>true</code> if the member <code>m</code> is 'part' of the family. </p>
  
  <p>Most importantly however, a member can be part of multiple families. </p>
  
  <p>I have a separate list of all the Members and wish to create a mapping between member and family for fast lookup.</p>
  
  <p>So I have something like this:</p>
  
  <pre><code>val allMembers : Set[Member] = getAllMembers()
  val allFamilies : Set[Family] = getAllFamilies()
  
  val memberFamilyMap : Map[Member, Set[Family]] = ???
  </code></pre>
  
  <p>What is the most efficient way to create the above <code>memberFamilyMap</code> given the <code>Family.member</code> function, and that a member can be a member of multiple families? I am trying to use a for-comprehension with generators of the two, but things got a bit hairy (I am a bit new to Scala)</p>