///<summary>Returns the value contained in the given potential value, if any, or else the result of evaluating the given alternative potential value function.</summary> public static May <T> Else <T>(this May <T> potentialValue, Func <May <T> > alternative) { if (alternative == null) { throw new ArgumentNullException("alternative"); } return(potentialValue.Match(e => e.Maybe(), alternative)); }
///<summary>Returns the value contained in the given potential value, if any, or else the result of evaluating the given alternative value function.</summary> public static T Else <T>(this May <T> potentialValue, Func <T> alternativeFunc) { if (alternativeFunc == null) { throw new ArgumentNullException("alternativeFunc"); } return(potentialValue.Match(e => e, alternativeFunc)); }
///<summary>Matches this potential value either into a function expecting a value or against an alternative value.</summary> public static TOut Match <TIn, TOut>(this May <TIn> potentialValue, Func <TIn, TOut> valueProjection, TOut alternative) { if (valueProjection == null) { throw new ArgumentNullException("valueProjection"); } return(potentialValue.Match(valueProjection, () => alternative)); }
///<summary>Returns the potential result of potentially applying the given function to this potential value.</summary> public static May <TOut> Bind <TIn, TOut>(this May <TIn> potentialValue, Func <TIn, May <TOut> > projection) { if (projection == null) { throw new ArgumentNullException("projection"); } return(potentialValue.Match(projection, () => NoValue)); }
///<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"); })); }