This is an an Option type implementaion using C# 9 records which closely follows the Option<'T> API as found in FSharp.Core
Operations against Options can be accessed through static functions or extension methods
Examples of the API can be found in the tests
Construct a new Some
new Some<int>(42);
Option.Some(42);
Construct a new None
new None<int>();
Option.None<int>();
Applies a map over the value of an Option
Option.Map(new Some<int>(42), x => x * 2); //Some 84
new Some<int>(42).Map(x => x * 2); //Some 84
Applies a binder over an Option
Option.Bind(new Some<int>(42), x => new Some<int>(x * 2)); //Some 84
new Some<int>(42).Bind(x => new Some<int>(x * 2)); //Some 84
Gets the value on an Option
Option.Get(new Some<int>(42)); //42
new Some<int>(42).Get(); //42
new None<int>().Get(); //ArgumentException
Gets the value on an Option, or returns the default if None
Option.DefaultValue(new Some<int>(42), 0); //42
new Some<int>(42).DefaultValue(0); //42
new None<int>().DefaultValue(0).Dump(); //0
Checks if the Option is Some
Option.IsSome(new Some<int>(42)); //True
new Some<int>(42).IsSome(); //True
new None<int>().IsSome(); //False
Checks if the Option is None
Option.IsNone(new Some<int>(42)); //False
new Some<int>(42).IsNone(); //False
new None<int>().IsNone(); //True
Converts the object into an Option, retuns None if the object is null
Option.OfObj("not a null string"); // Some("not a null string")
Option.OfObj<string>(null); // None<string>()
Returns the object from an Option, returns null if the Option is null
Option.ToObj(new Some<string>("not a null string")); // "not a null string"
new Some<string>("not a null string").ToObj(); // "not a null string"
Option.ToObj(new None<string>()); // null
new None<string>().ToObj(); // null
new None<int>() == new None<int>() //True
new None<int>() == new Some<int>(42) //False
new Some<int>(42) == new Some<int>(42) //True
new Some<int>(42) == new Some<int>(99) //False