I think it's more interesting if you don't bother, and just use where on group.Key, in which case if there is no grouping, you get the empty enumerable for free. I also used .Take(1) instead of FirstOrDefault(), then selected over the 0 or 1 element enumerable,
instead of explicitly handling the empty case, which I find far too satisfying for words

I'm pretty happy with this, though there really should be better "control" Linq operators.

static IEnumerable<T> QuickSort<T>(IEnumerable<T> enumerable) where T : IComparable<T> {
var ps = enumerable.Take(1);
var pt = from pivot in ps from x in enumerable.Skip(1)
group x by 0 < x.CompareTo(pivot);
var lt = pt.Where(g => !g.Key).SelectMany(g => QuickSort(g));
var gt = pt.Where(g => g.Key).SelectMany(g => QuickSort(g));
return lt.Concat(ps).Concat(gt);
}

## Comments

## C9 Lectures: Dr. Erik Meijer - Functional Programming Fundamentals, Chapter 1 of 13

I think it's more interesting if you don't bother, and just use where on group.Key, in which case if there is no grouping, you get the empty enumerable for free. I also used .Take(1) instead of FirstOrDefault(), then selected over the 0 or 1 element enumerable, instead of explicitly handling the empty case, which I find far too satisfying for words

## C9 Lectures: Dr. Erik Meijer - Functional Programming Fundamentals, Chapter 1 of 13

I'm pretty happy with this, though there really should be better "control" Linq operators.