title: Unique combinations of list
body: <p>Absolute mind blank on this. It's been one of those days. But I have been looking for a solution for getting unique combinations of a list of items of a certain length. e.g., given a list [a, b, c] and a length of 2, it will return [a,b] [a,c] [b,c] but not [b,a] [c,a] [c,b]</p>
  
  <p>For this I found numerous pieces of code, but none which seems to fit. The following code seemed best fit and I've been trying to alter it for my needs:</p>
  
  <pre><code>// Returns an enumeration of enumerators, one for each permutation
  // of the input.
  public static IEnumerable&lt;IEnumerable&lt;T&gt;&gt; Permute&lt;T&gt;(IEnumerable&lt;T&gt; list, int count)
  {
      if (count == 0)
      {
          yield return new T[0];
      }
      else
      {
          int startingElementIndex = 0;
          foreach (T startingElement in list)
          {
              IEnumerable&lt;T&gt; remainingItems = AllExcept(list, startingElementIndex);
  
              foreach (IEnumerable&lt;T&gt; permutationOfRemainder in Permute(remainingItems, count - 1))
              {
                  yield return Concat&lt;T&gt;(
                      new T[] { startingElement },
                      permutationOfRemainder);
              }
              startingElementIndex += 1;
          }
      }
  }
  
  // Enumerates over contents of both lists.
  public static IEnumerable&lt;T&gt; Concat&lt;T&gt;(IEnumerable&lt;T&gt; a, IEnumerable&lt;T&gt; b)
  {
      foreach (T item in a) { yield return item; }
      foreach (T item in b) { yield return item; }
  }
  
  // Enumerates over all items in the input, skipping over the item
  // with the specified offset.
  public static IEnumerable&lt;T&gt; AllExcept&lt;T&gt;(IEnumerable&lt;T&gt; input, int indexToSkip)
  {
      int index = 0;
      foreach (T item in input)
      {
          if (index != indexToSkip) yield return item;
          index += 1;
      }
  }
  </code></pre>
  
  <p>This does what it is supposed to do, but it returns ALL permutations, regardless of them being unique. I've tried to get my head around which piece, if any, of this code to change to get the unique values. Or is the a better way to implement this functionality?</p>