Contents tagged with functional

  • The resultor pattern

    In this short post belonging to the series about extending the world of Linq, I'll talk about an interesting way to leverage anonymous types through a pattern we use at work. We all know what they are, and we all know their most important limitation: once defined, an anonymous type cannot be passed to other functions or returned to the caller of the function which defined it (we are talking about language features, and we don't consider any technique based on reflection or other knowledge about the runtime internal structure of such types). It is quite common to write functions which return complex values, and if we want to make them reusable we need at some point to define some structure representing the result of the computation. We could use tuples, but they are not that good at communicating information, so we must surrender and define small DTOs just to represent those answers, just because anonymous type cannot cross the boundaries of a function. But is that completely true?

  • Extending the world, step 4

    Last time we introduced a new simple exercise, where we have a computation which might fails and we want to to try to remove all the noise that the error handling introduces all around the algorithm. We talked about Monads (in a very simplified way) and we defined a way we could write our computation inside a Linq expression, using a Monad to isolate the unwanted error handling code. What we still have to do is actually implement this new Monad and see how we can leverage this concepts and strategies to reach our goal.

  • Extending the world, step 3

    So far in our series we have seen how Linq is a world that can be extended if we craft our types the right way. We learned that Linq is definitely not just for IEnumerable or IQueryable, and I'm more and more convinced that what's most interesting about Linq is the way it guides you to write more functional code. I'm not a functional programmer (yet), so please do not expect too much knowledge about that from my posts, but I'm slowly gaining a more functional view on things, and I'm feeling that it's a good thing to have. There are a few aspects of functional programming that Linq tries to enforce:

  • Extending the world, step 2

    In the previous episode of this short series, I showed how you can define a type in a way that enables it to participate to Linq queries. Linq query syntax defines a set of operators, which are mapped to methods that types involved in a Linq query must provide. If they natively do not, we can still make them work because extension methods come to the rescue. How those methods should be named and shaped is clearly documented, and it would be too much to be explained here, so I will skip these details. I'll go back to our exercise and I'll use it to give you some more details about a couple of interesting points.

  • Extending the world, step 1

    After the general introduction to this short series of post, I would like to set up a sort of roadmap, defining the goals that I have while writing this stuff. But first, a sort of disclaimer: I'm not a big expert of these things at all, and I'm quite new to this kind of approach, but that's exactly the reason why I want to write about it, to illustrate things from the point of view of someone who's really learning to use this new mindset and the related techniques, because I know there are a lot of guys like me out there :) The code I will show will be written by myself in a sort of "learn by trial" process, but it will be strongly inspired by several sources, which I will try to mention as most precisely as possible. If someone reading these posts will find errors or omissions his comments will be welcomed.

  • Extending the world

    After a few months I'm back to write on my blog, but to be honest I had a good excuse, since my wife and I have dealt with a move abroad (I'll talk about it separately), which is not exactly something trivial. However, we are slowly returning to normal, and today I managed to get a little time to write this post.