///<summary>Returns the value contained in the given potential value as a nullable type, returning null if there is no contained value.</summary> public static T?AsNullable <T>(this May <T> potentialValue) where T : struct { return(potentialValue.Select(e => (T?)e).ElseDefault()); }
///<summary>Returns the value contained in the given potential value, if any, or else the given alternative potential value.</summary> public static May <T> Else <T>(this May <T> potentialValue, May <T> alternative) { return(potentialValue.Else(() => alternative)); }
///<summary>Returns the value contained in the potential value, or throws an InvalidOperationException if it contains no value.</summary> public static T ForceGetValue <T>(this May <T> potentialValue) { return(potentialValue.Match( e => e, () => { throw new InvalidOperationException("No Value"); })); }
///<summary>Flattens a doubly-potential value, with the result containing a value only if both levels contained a value.</summary> public static May <T> Unwrap <T>(this May <May <T> > potentialValue) { return(potentialValue.Bind(e => e)); }
///<summary>Returns the value contained in the given potential value, if any, or else the type's default value.</summary> public static T ElseDefault <T>(this May <T> potentialValue) { return(potentialValue.Else(default(T))); }