3 ms·
Whilst non-nullable references are useful, that isn't what Option is trying to solve. The problem with null references is that when you're handed a reference t
by louthy 11y ago
Whilst non-nullable references are useful, that isn't what Option is trying to solve. The problem with null references is that when you're handed a reference to an object of type T - the type system is saying to you: "This is the contract I will honour". Except it doesn't when the reference is null.
However the functionality of a null reference type is useful, because it allows a function to return 'no value'. So the goal of an Option type should be to expose the contract for T when there's a value and remove the contract when there's no-value.
The programmer is then explicitly forced to acknowledge the two states that the value could be.
Shameless plug - My C# implementation of Option which is possibly the most complete example out there (at least in C# world):
https://github.com/louthy/language-ext/blob/master/LanguageExt.Core/Option.cs https://github.com/louthy/language-ext/blob/master/LanguageE...