예제 #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);
        }
예제 #2
0
 public static Option <OUT> Try <OUT>(Func <OUT> function)
 {
     try
     {
         return(Option <OUT> .AsOption(function.Invoke()));
     }
     catch
     {
         return(Option <OUT> .None);
     }
 }
예제 #3
0
 public Option <OUT> Select <OUT>(Func <T, OUT> selector)
 {
     return(IsSome
         ? Option <OUT> .AsOption(selector.Invoke(_value))
         : Option <OUT> .None);
 }
예제 #4
0
 public Option <OUT> OfType <OUT>()
 {
     return(IsSome
         ? _value is OUT ? Option <OUT> .AsOption((OUT)(object)_value) : Option <OUT> .None
         : Option <OUT> .None);
 }