Пример #1
0
        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>());
        }
Пример #2
0
 public static Option <TValue> OfType <TValue>(this Option <object> option)
 => option.Match(value => Option.Create(value is TValue, () => (TValue)value), Option.None <TValue>);