Solving Fizz Buzz using LINQ in C# The Fizz Buzz challenge is well-known and should not need any explanations, right?
I recently got a bit bored and came up with a solution for Fizz Buzz using LINQ and even asynchronous code and a lot of extension methods. Actually, it's only Extension methods!
So, I thought, let's share it and have a review of my code!

using System;
using System.Collections.Generic;
using System.Linq;

namespace FizzBuzzApp
{
    using IntEnum = IEnumerable&lt;int&gt;;
    using Pair = KeyValuePair&lt;int, string&gt;;
    using PairEnum = IEnumerable&lt;KeyValuePair&lt;int, string&gt;&gt;;
    using StringEnum = IEnumerable&lt;string&gt;;

    public static class FizzBuzzClass
    {
        public static T DoThis&lt;T&gt;(this T data, Action&lt;T&gt; action) { action(data); return data; }
        public static T DoThis&lt;T&gt;(this T data, Action action) { action(); return data; }
        public static IEnumerable&lt;T&gt; DoThis&lt;T&gt;(this IEnumerable&lt;T&gt; data, Action&lt;T&gt; action) { foreach (var item in data) { action(item); yield return item; } }

        public static T IfThis&lt;T&gt;(this T data, Func&lt;T, bool&gt; condition, Func&lt;T, T&gt; action) =&gt; condition(data) ? action(data) : data;
        public static T IfThis&lt;T&gt;(this T data, Func&lt;T, bool&gt; condition, Func&lt;T, T&gt; onTrue, Func&lt;T, T&gt; onFalse) =&gt; condition(data) ? onTrue(data) : onFalse(data);

        public static IntEnum MakeIntArray(this int count, int start = 0) =&gt; Enumerable.Range(start, count);

        public static Pair NewPair(this int key) =&gt; new Pair(key, string.Empty);
        public static Pair NewPair(this Pair pair, string data) =&gt; new Pair(pair.Key, data.Trim());
        public static PairEnum MakePairs(this IntEnum data, bool asynchronous) =&gt; asynchronous ? data.AsParallel().Select(NewPair) : data.Select(NewPair);
        public static IOrderedEnumerable&lt;Pair&gt; SortPairs(this IEnumerable&lt;Pair&gt; data) =&gt; data.OrderBy(p =&gt; p.Key);

        public static bool IsFizz(this Pair data) =&gt; data.Key % 3 == 0;
        public static Pair DoFizz(this Pair data) =&gt; data.NewPair("Fizz " + data.Value);
        public static Pair Fizz(this Pair data) =&gt; data.IfThis(IsFizz, DoFizz);
        public static PairEnum Fizz(this PairEnum data, bool asynchronous) =&gt; asynchronous ? data.AsParallel().Select(Fizz) : data.Select(Fizz);

        public static bool IsBuzz(this Pair data) =&gt; data.Key % 5 == 0;
        public static Pair DoBuzz(this Pair data) =&gt; data.NewPair(data.Value + " Buzz");
        public static Pair Buzz(this Pair data) =&gt; data.IfThis(IsBuzz, DoBuzz);
        public static PairEnum Buzz(this PairEnum data, bool asynchronous) =&gt; asynchronous ? data.AsParallel().Select(Buzz) : data.Select(Buzz);

        public static bool IsNumber(this Pair data) =&gt; string.IsNullOrEmpty(data.Value);
        public static Pair DoNumber(this Pair data) =&gt; data.NewPair(data.Key.ToString());
        public static Pair Number(this Pair data) =&gt; data.IfThis(IsNumber, DoNumber);
        public static PairEnum Number(this PairEnum data, bool asynchronous) =&gt; asynchronous ? data.AsParallel().Select(Number) : data.Select(Number);

        public static StringEnum Values(this PairEnum data) =&gt; data.Select(p =&gt; p.Value);
        public static string Combine(this StringEnum data) =&gt; string.Join(", ", data);

        public static string FizzBuzz(this int count, bool asynchronous = false) =&gt;
            count.MakeIntArray()
                 .MakePairs(asynchronous)
                 .Fizz(asynchronous)
                 .Buzz(asynchronous)
                 .Number(asynchronous)
                 .SortPairs()
                 .Values()
                 .Combine();
}


To use it, just use 100.FizzBuzz(true); for the asynchronous version.
Now, the thing is that it's full one-liner extension methods. It's definitely not something a beginner would write. But is it well-written for experts?
Parallel computing and asynchonous computing are two separate things. While they might be similar in some cases, the two terms have two very distinct meanings in C#-land:


Asynchronous computing is used for the async/await and Task&lt;T&gt; idioms.
Parallel computing is what you are doing here, using plinq: processing streams of data in different threads in parallel.


With that said, you're not using the features of Plinq to the fullest. Instead of passing the (incorrectly named) asynchronous to each of the methods, count.MakeIntArray().AsParallel() would have sufficed to make the entire thing parallel.



I think you went a bit overboard with the amount of extension methods you created, while gaining little for it in return. What if a new request would come to say something new on every number modulo 10? Now you have to make changes in 4 methods (or more accurately, create 4 more methods) to account for these changes!

Instead you could have made the Fizz and Buzz methods two versions of a more generic Substitute method:

public string Substitute(int number, Func&lt;int, bool&gt; when, string with);