title: join two collections on a custom condition
body: <p>I have two collections, <code>IEnumerable&lt;A&gt; as</code> and <code>IEnumerable&lt;B&gt; bs</code></p>
  
  <p>I also have a predicate <code>Func&lt;A, B, boolean&gt; predicate</code></p>
  
  <p>I would like to join <code>as</code> and <code>bs</code> together to get something equivalent to an <code>IEnumerable&lt;IGrouping&lt;A, B&gt;&gt; joined</code> such that for each element <code>group</code> in <code>joined</code>, for each element <code>b</code> in <code>group</code>, <code>predicate(group.key, b)</code> holds.</p>
  
  <p>To get such a grouping, there usually is the <code>GroupBy</code> extension method, but that cant operate based on a custom predicate.</p>
  
  <p>I considered two approaches, one just building a collection with nested loops, the other doing the same with <code>Aggregate</code>. Both look really ugly. Is there a better way to do this?</p>
  
  <p>In this particular case, for each element <code>b</code> in <code>bs</code> there is exactly one <code>A</code> in <code>as</code> for which the predicate holds, and I don't mind relying on that property if that makes for a nicer solution.</p>
  
  <p>As far as I can see, in the general case it can't make for a better asymptotic runtime complexity than <code>O(n * m)</code> where <code>n</code> is the length of <code>as</code> and <code>m</code> is the length of <code>bs</code>. I'm OK with that.</p>