First off, it is important to note which namespaces we will need to include (I hate when I have to google or guess since the writer doesn’t include them in the tutorial/post). This one is nice and easy and only requires:

With this we make use of the polymorphism in C# and have the type this is available on be IEnumerable (which includes just about all, if not all, of the generic collections). Next you will notice:

Func<T,T> f

This is declaring a delegate that takes type T and returns type T. Since there needs to be passing of a result from function g to function f, we need to use K combinator. This also means that the return type must be the same type as the input.

We create a List of type T so that we can hold our results. We then loop through each item in the original Enumerable (me) and apply f(g(i)) to them while adding it to the output list. This part should be self-explanatory. We then finish it up with:

Again, self explanatory, but since we want to keep it as generic as possible we will pass it back as an Enumerable type instead of a list.

While the B combinator has a little more complexity than the K combinator, it is still a cinch to implement in C#. Please stay tuned because I will definitely be updating this with more of the combinators.