Exemplo n.º 1
0
 ///<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()));
 }
Exemplo n.º 2
0
 ///<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));
 }
Exemplo n.º 3
0
 ///<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))));
 }
Exemplo n.º 4
0
 ///<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));
 }