public static async Task <Option <TValue> > WhereAsync <TValue>(this Option <TValue> option, Func <TValue, Task <bool> > predicate) { if (predicate == null) { throw new ArgumentNullException(nameof(predicate)); } if (option.TryGetValue(out var some)) { return(Option.Create(await predicate.Invoke(some), some)); } return(Option.None <TValue>()); }
public static Option <TValue> OfType <TValue>(this Option <object> option) => option.Match(value => Option.Create(value is TValue, () => (TValue)value), Option.None <TValue>);