6 lines long quicksort in C#
That’s it. Well, this is not very efficient, and shouldn’t be used in real-world scenarios, but it shows how powerful LINQ can be.
We compare this code with imperative version and even with Haskell below.
So, let’s compare it with imperative code I wrote in 2011 being a first-year student (again, shouldn’t be used in the real world):
As you can see, functional version is in fact much easier to understand, and much shorter, of course.
The implementation is actually adopted version of Haskell script from Erik Meijer’s MOOC “Functional Programming 101”, so let’s compare with Haskell version: