Exemple #1
0
        public static Option <T> TryFind <T>(this IEnumerable <T> self, Func <T, bool> predicate)
        {
            var list = self.Where(predicate)
                       .Take(1)
                       .ToList();

            return(list.Count == 1 ? Option <T> .AsOption(list.FirstOrDefault()) : Option <T> .None);
        }
Exemple #2
0
 public static Option <OUT> Try <OUT>(Func <OUT> function)
 {
     try
     {
         return(Option <OUT> .AsOption(function.Invoke()));
     }
     catch
     {
         return(Option <OUT> .None);
     }
 }
Exemple #3
0
 public Option <OUT> Select <OUT>(Func <T, OUT> selector)
 {
     return(IsSome
         ? Option <OUT> .AsOption(selector.Invoke(_value))
         : Option <OUT> .None);
 }
Exemple #4
0
 public Option <OUT> OfType <OUT>()
 {
     return(IsSome
         ? _value is OUT ? Option <OUT> .AsOption((OUT)(object)_value) : Option <OUT> .None
         : Option <OUT> .None);
 }