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