Functional Inspiration – Irrelevantable, part 2

Trying to express something more than Nullable<T>

Friday evening, the girls are in bed, the wife is out with friends… It seems that it is the perfect time to finish this post !

This is the third entry of a blog series about how functional programming, and the F# training I recently went to, gives me inspiration in my day-to-day work in C#. This post will show how you can build in F# the Irrelevantable type previously built in C#.

Let’s go straight to the code, here is the structure :

type Irrelevantable<'a> =
| Relevant of 'a
| Absent
| Irrelevant

Using a very simple discriminated union type, we can easily express the three distinct cases needed.

Let’s now see how this type can be used. I first define a Product Type and a sample products list :