DEV Community

Discussion on: Show Me the Article You're Most Proud Of And I'll Read Every Single One of Them

Collapse
 
sethcalebweeks profile image
Caleb Weeks •

This is my first post on DEV. I did not expect to have a lot of readers for my first post, but it's my most read by far. I think maybe DEV promotes first posts?
dev.to/sethcalebweeks/haskell-quic...

Collapse
 
georgekobaidze profile image
Giorgi Kobaidze •

Fun read, and a good use of the algorithm as a vehicle for explaining Haskell syntax rather than the other way round.

Coming from C#, the same shape falls out of LINQ almost unchanged:

static IEnumerable<T> Qs<T>(IReadOnlyList<T> xs) where T : IComparable<T> =>
    xs.Count == 0
        ? Enumerable.Empty<T>()
        : Qs(xs.Skip(1).Where(a => a.CompareTo(xs[0]) <= 0).ToList())
            .Append(xs[0])
            .Concat(Qs(xs.Skip(1).Where(a => a.CompareTo(xs[0]) > 0).ToList()));
Enter fullscreen mode Exit fullscreen mode

Some comments have been hidden by the post's author - find out more