PutridParrot.Options/OptionExtensions.cs
/// <summary>
/// If the Option has a value and the predicate returns true then 
/// returns the Option otherwise returns a None
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="option"></param>
/// <param name="predicate"></param>
/// <returns></returns>
If the Option has a value and the predicate returns true then
returns the Option otherwise returns a None
If the Option has a value and the predicate returns true then returns the Option otherwise returns a None
public static Option<T> If<T>(this Option<T> option, Predicate<T> predicate)
        {
            if (predicate == null)
            {
                throw new ArgumentNullException(nameof(predicate));
            }
            return option is Some<T> some && predicate(some.Value) ?
                option : Option<T>.None;
        }
public static Option < T > If < T > ( this Option < T > option , Predicate < T > predicate ) { if ( predicate == null ) { throw new ArgumentNullException ( nameof ( predicate ) ) ; } return option is Some < T > some && predicate ( some . Value ) ? option : Option < T > . None ; }
If the Option has a value and the predicate returns true then
returns the Option otherwise returns a None
If the Option has a value and the predicate returns true then returns the Option otherwise returns a None
None
Option<T>
this
predicate
Predicate<T>
None
option
None
typeparam
None