title: Set of maximal independent subsets via a c# generator
body: <p>I want to find all subsets of a given set that are mutually exclusive and contain as many elements of the superset as possible. Where the user defines a meaning for exclusiveness:</p>
  
  <pre><code>bool exclusion&lt;T&gt;(T a, T b)
  </code></pre>
  
  <p>where at least <code>exclusion(a, b) == exclusion(b, a)</code> holds.</p>
  
  <p>And <code>exclusion(a, b) == true</code> is guaranteed if <code>a.Equals(b) == true</code></p>
  
  <p>My code looks like this:</p>
  
  <pre><code>public static HashSet&lt;HashSet&lt;T&gt;&gt; MutuallyExclusive&lt;T&gt;(this IEnumerable&lt;T&gt; available, Func&lt;T, T, bool&gt; exclusion) {
      HashSet&lt;HashSet&lt;T&gt;&gt; finished = new HashSet&lt;HashSet&lt;T&gt;&gt;(new HashSetEquality&lt;T&gt;());
      Recursion&lt;T&gt;(available, new HashSet&lt;T&gt;(), finished, exclusion);
      return finished;
  }
  
  private static void Recursion&lt;T&gt;(IEnumerable&lt;T&gt; available, HashSet&lt;T&gt; accepted, HashSet&lt;HashSet&lt;T&gt;&gt; finished, Func&lt;T, T, bool&gt; exclusion) {
      if (!available.Any())
          finished.Add(accepted);
      else
          foreach (T a in available)
              Recursion&lt;T&gt;(available.Where(b =&gt; !exclusion(a, b)), new HashSet&lt;T&gt;(accepted) { a }, finished, exclusion);
  }
  
  private class HashSetEquality&lt;T&gt; : IEqualityComparer&lt;HashSet&lt;T&gt;&gt; {
      public bool Equals(HashSet&lt;T&gt; x, HashSet&lt;T&gt; y) {
          if (x.Count != y.Count)
              return false;
          return x.All(t =&gt; y.Contains(t));
      }
  
      public int GetHashCode(HashSet&lt;T&gt; obj) {
          return obj.Aggregate(0, (i, t) =&gt; i ^ t.GetHashCode());
      }
  }
  </code></pre>
  
  <p>Is there a way to turn this code into an iterator moving through the accepted values one by one?</p>
  
  <p><strong>Edit:</strong></p>
  
  <p>It seems I was I little unprecise in my question, sorry. I was actually searching for a Generator for deffered execution. So that every time you call it only the next accepted set is calculated</p>