PutridParrot.Options/OptionalExtensions.cs
/// <summary>
/// If the Optional has some value then call the
/// supplied function to return a result else
/// return a default/alternate value
/// </summary>
/// <typeparam name="T"></typeparam>
/// <typeparam name="TResult"></typeparam>
/// <param name="optional"></param>
/// <param name="someValue"></param>
/// <param name="noneValue"></param>
/// <returns></returns>
If the Optional has some value then call the
supplied function to return a result else
return a default/alternate value
If the Optional has some value then call the supplied function to return a result else return a default / alternate value
public static TResult Match<T, TResult>(this Optional<T> optional,
            Func<T, TResult> someValue,
            TResult noneValue = default(TResult))
        {
            if (someValue == null)
            {
                throw new ArgumentNullException(nameof(someValue));
            }
            return optional.IsSome ? someValue(optional.Value) : noneValue;
        }
public static TResult Match < T , TResult > ( this Optional < T > optional , Func < T , TResult > someValue , TResult noneValue = default ( TResult ) ) { if ( someValue == null ) { throw new ArgumentNullException ( nameof ( someValue ) ) ; } return optional . IsSome ? someValue ( optional . Value ) : noneValue ; }
If the Optional has some value then call the
supplied function to return a result else
return a default/alternate value
If the Optional has some value then call the supplied function to return a result else return a default / alternate value
None
Optional<T>
this
<not_specific>
someValue
Func<T, TResult>
None
noneValue
TResult
None
optional
<not_specific>
None
typeparam
None
typeparam
None