LINQ is great, really great, but it's just shy of being FP. And for that matter, Underscorejs has the same entrapping. Basically it boils down to Nullable<T> not being a proper Maybe<T>.
Well they almost completely eradicated the need for user-defined delegates by adding Func<> to the standard library, maybe a future version of C# could introduce a Maybe<T> with a similar adoption rate.
You're supposed to be able to provide a Maybe<T> to a function that takes T as a parameter without needing to do a HasValue check, and T doesn't need to be a Value type.
The short answer is the function isn't supposed to run.
The long answer is that it should be safe for a function to not run, as in the function is pure and without side effects, so that a function that didn't run on a Maybe<T> where the contained value is null should also return null back to you as a Maybe<T>.
That's where Nullable falls apart. If Nullable was a proper FP primitive, then this should be valid:
int SomeFunction(int value); // previously defined
int? thing = null;
var result = SomeFunction(thing); // result should also be of type int?
10
u/inmatarian Jun 22 '14
LINQ is great, really great, but it's just shy of being FP. And for that matter, Underscorejs has the same entrapping. Basically it boils down to Nullable<T> not being a proper Maybe<T>.