///<summary>Returns the result of potentially applying a function to this potential value.</summary> public static May <TOut> Select <TIn, TOut>(this May <TIn> value, Func <TIn, TOut> projection) { if (projection == null) { throw new ArgumentNullException("projection"); } return(value.Bind(e => projection(e).Maybe())); }
///<summary>Returns the same value, unless the contained value does not match the filter in which case a no value is returned.</summary> public static May <T> Where <T>(this May <T> value, Func <T, bool> filter) { if (filter == null) { throw new ArgumentNullException("filter"); } return(value.Bind(e => filter(e) ? e.Maybe() : NoValue)); }
///<summary>Projects optional values, returning a no value if anything along the way is a no value.</summary> public static May <TOut> SelectMany <TIn, TMid, TOut>(this May <TIn> source, Func <TIn, May <TMid> > maySelector, Func <TIn, TMid, TOut> resultSelector) { if (maySelector == null) { throw new ArgumentNullException("maySelector"); } if (resultSelector == null) { throw new ArgumentNullException("resultSelector"); } return(source.Bind(s => maySelector(s).Select(m => resultSelector(s, m)))); }
///<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)); }