Option values

The optional values are a way of representing uncertain data, it is not always possible to be sure of the result of some operation.

These type of value are a new proposal rather than the nullable types.

The nullable types are problematics because these types looks like a real value, ocasionally this nullable values can cause an error from a tentative to access a method or property from an object that contains a null value. These exception ara called ArgumentNullException.

Option values are also a way to encapsulate data without allows access to this data when it contains none. In some programming languages like Haskell, for instance, the Option type is represented by the Maybe type. A different name to the same concept.

An Option value can be in one of these two states:

  • Some

  • None

In this library propose, it's only possible to access a value from an Option type when these type is in Some state.

As you already must have noticed, the idea behind nullable and Option types are very similar, but in general terms, the Option type is more powerful, you avoid exceptions and you can use it with reference types as well.

The implementations behind this concepts were done in two steps: the Option type and the module.

Last updated