SUMMARY

The use of Option<T> types instead of null values is a different strategy to handle cases where the absence of information is important. Option<T> types are a cleaner approach than null values because there are no differences in their use for value and reference types. They are also more powerful because they take a “metadata” approach to store additional information about a value, thereby enabling the full use of a type’s value range, including null itself.

Another important argument in favor of Option<T> is the possibility of viewing it as a monad, which enables the chaining of operations that work on the type without the need of explicit special case handling. This topic is discussed in depth in Chapter 17.

Get Functional Programming in C#: Classic Programming Techniques for Modern Projects now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.