Пример #1
0
 /// <summary>
 /// Projects the current type of option into a new type of option and flattens the result (Linq SelectMany).
 /// </summary>
 /// <typeparam name="R">The type of the option returned by the transform function.</typeparam>
 /// <param name="f">A transform function to apply to the current option.</param>
 public OptionF <R> Bind <R>(Func <T, OptionF <R> > f)
 {
     if (this.IsNone)
     {
         return(OptionF <R> .None());
     }
     else
     {
         return(f(this.Value));
     }
 }
Пример #2
0
 /// <summary>
 /// Projects the current type of option into a new type of option (Linq Select).
 /// </summary>
 /// <typeparam name="R">The type of the option returned by the transform function.</typeparam>
 /// <param name="f">A transform function to apply to the current option.</param>
 public OptionF <R> Map <R>(Func <T, R> f)
 {
     if (this.IsNone)
     {
         return(OptionF <R> .None());
     }
     else
     {
         return(OptionF <R> .Some(f(this.Value)));
     }
 }
Пример #3
0
 /// <summary>
 /// Returns true if the option contains a value and false otherwise.
 /// </summary>
 /// <param name="some">The value of the option.</param>
 public static bool MatchSomeF <T>(this OptionF <T> opt, out T some)
 {
     if (opt.IsSome)
     {
         some = opt.Value;
         return(true);
     }
     else
     {
         some = default(T);
         return(false);
     }
 }
Пример #4
0
 /// <summary>
 /// Returns true if the option does not contain a value and false otherwise.
 /// </summary>
 public static bool MatchNoneF <T>(this OptionF <T> opt)
 {
     return(opt.IsNone);
 }