concept option type in category c#

This is an excerpt from Manning's book Real-World Functional Programming with Examples in F# and C#.
In C#, we have to specify the types explicitly most of the time. When writing a method, we have to specify what the types of its parameters are and what the return type is. In F# we don’t typically write any types. F# language is also statically typed. In F#, every expression has types as well, but F# uses a mechanism called type inference to deduce the types automatically at compile-time. Static typing in a functional language such as F# guarantees even more than it does in C#. We’ll see an example in chapter 5 when we discuss the option type, which can be used to avoid using uninitialized references.
In this section, we’ll apply the techniques from the previous section to alternative values. When working with tuples, we found it very helpful to write a function that works with one element from the tuple. Similarly, when working with alternative values, we’ll need a higher-order function that performs some operation on one or more of the alternatives. We’ll follow the examples from the previous chapter, so we’ll start with a schedule type and then we’ll look at the option type.
One of the most important alternative values in F# is the option type. To recap what we’ve seen in the previous chapter, it gives us a safe way to represent the fact that value may be missing. This safety means that we can’t easily write code that would assume that the value is present and would fail if the option type represents a missing value. Instead, we have to use pattern matching and write code for both of the cases. In this section, we’ll learn about two useful functions for working with the option type.
Listing 12.22. Query operators for option type (C#)
static class OptionExtensions { public static Option<R> Select<S, R> (this Option<S> source, Func<S, R> selector) { return source.Map(selector); ❶ } public static Option<R> SelectMany<S, V, R> (this Option<S> source, Func<S, Option<V>> valueSelector, Func<S, V, R> resultSelector) { return source.Bind(sourceValue => ❷ valueSelector(sourceValue).Map(resultValue => ❸ resultSelector(sourceValue, resultValue))); } }