Summary
Pattern matching is a form of dispatch to choose the correct variant of functions to be called. In other words, its concept is close to the if
conditional expression because we have to decide the correct selection by providing specific input. The matching process can be simplified to make it implement a functional approach. We discussed the switch
case and then refactored it using LINQ so it became functional.
We learned the definition of monad itself: a type that uses the Monad pattern, which is a design pattern for types. In C#, there are some types that have implemented Monad naturally; they are Nullable<T>
, IEnumerable<T>
, Func<T>
, Lazy<T>
, and Task<T>
.
For now, we have enough knowledge about functional programming in C#. In the next chapter, we will use everything you learned in this and previous chapters to develop an application that implements a functional approach. In the upcoming chapter, we will transform imperative code into functional code...