I'm playing with QuickSort and LINQ, and want to separate the sequence into item before, equal-to, and after a pivot.
Here's what I have so far:
public static Tuple<IEnumerable<T>, IEnumerable<T>, IEnumerable<T>> ComparativeWhere<T>(this IEnumerable<T> source, T t)
where T : IComparable<T>
{
return new Tuple<IEnumerable<T>, IEnumerable<T>, IEnumerable<T>>(
source.Where(x => x.CompareTo(t) < 0),
source.Where(x => x.CompareTo(t) == 0),
source.Where(x => x.CompareTo(t) > 0)
);
}
What's the best way to do this? Is this the best implementation, or is there a better one? Or should I be using a library function I don't know about?