Пример #1
0
 public static Maybe <V> SelectMany <T, U, V>(this Maybe <T> maybe,
                                              Func <T, Maybe <U> > selector,
                                              Func <T, U, V> project)
 {
     return(maybe.GetValueOrDefault(
                x => selector(x).GetValueOrDefault(u => project(x, u), Maybe <V> .None),
                Maybe <V> .None));
 }
Пример #2
0
 public static List <T> ToList <T>(this Maybe <T> maybe)
 {
     return(maybe.GetValueOrDefault(value => new List <T> {
         value
     }, new List <T>()));
 }
Пример #3
0
 public static K Unwrap <T, K>(this Maybe <T> maybe, Func <T, K> selector, K defaultValue = default(K))
 {
     return(maybe.GetValueOrDefault(selector, defaultValue));
 }
Пример #4
0
 public static T Unwrap <T>(this Maybe <T> maybe, T defaultValue = default)
 {
     return(maybe.GetValueOrDefault(defaultValue));
 }
Пример #5
0
 public static void Deconstruct <T>(this Maybe <T> result, out bool hasValue, out T value)
 {
     hasValue = result.HasValue;
     value    = result.GetValueOrDefault();
 }