title: C# functional quicksort is failing
body: <p>I'm trying to implement quicksort in a functional style using C# using linq, and this code randomly works/doesn't work, and I can't figure out why.<br>
  Important to mention: When I call this on an array or list, it works fine. But on an unknown-what-it-really-is IEnumerable, it goes insane (loses values or crashes, usually. sometimes works.)<br>
  The code:  </p>
  
  <blockquote>
  <pre><code>   public static IEnumerable&lt;T&gt; Quicksort&lt;T&gt;(this IEnumerable&lt;T&gt; source)
          where T : IComparable&lt;T&gt;
      {
          if (!source.Any())
              yield break;
          var pivot = source.First();
          var sortedQuery = source.Skip(1).Where(a =&gt; a.CompareTo(source.First()) &lt;= 0).Quicksort()
                            .Concat(new[] { pivot })
                            .Concat(source.Skip(1).Where(a =&gt; a.CompareTo(source.First()) &gt; 0).Quicksort());
          foreach (T key in sortedQuery)
              yield return key;
      }
  </code></pre>
  </blockquote>
  
  <p>Can you find any faults here that would cause this to fail?</p>
  
  <p><strong>Edit:</strong> Some better test code:</p>
  
  <blockquote>
  <pre><code>        var rand = new Random();
          var ienum = Enumerable.Range(1, 100).Select(a =&gt; rand.Next());
          var array = ienum.ToArray();
          try
          {
              array.Quicksort().Count();
              Console.WriteLine("Array went fine.");
          }
          catch (Exception ex)
          {
              Console.WriteLine("Array did not go fine ({0}).", ex.Message);
          }
          try
          {
              ienum.Quicksort().Count();
              Console.WriteLine("IEnumerable went fine.");
          }
          catch (Exception ex)
          {
              Console.WriteLine("IEnumerable did not go fine ({0}).", ex.Message);
          }
  </code></pre>
  </blockquote>