Functional Card Deck in C#

October 11, 2018 c#, fp

I've been inspired lately by Mark Seemann's series of posts about Applicative Functors. One of the latest posts is an example about creating a full deck of cards. Most of posts up to this point have contained a C# example but for some reason this one didn't. This inspired me to take a shot at it.

Read More

A neat way to curry in C#

May 25, 2018 c#, fp

I was reading an older blogpost from Mike Hadlow about Partial Application in C# in which he discusses how Partial Application can be implemented in C# via Currying. Although I appreciate his example of implementing currying via extsion methods, the syntax is hideous. There is a suggestion in the comments though that I found to be a much better solution.

// Define a local function Add. int Add(int a, int b) => a + b; // Here we do the currying. Func<int, int> add3 = (b) => Add(3, b); // This will print 5. Console.WriteLine(add3(2)); // Curry one more time so that we have // a function that simply produces 5. Func<int> five = () => add3(2); // This will also print 5. Console.WriteLine(five());

Lambda Collection Wrappers

April 26, 2018 c#, lambda, fp

I've been reading a lot as of late about functional programming and I try to incorperate as much as possible into my everyday programming. One trick that I've definitely started using is wrapping collections in lambda functions.

Read More