PutridParrot.Options/OptionalExtensions.cs
/// <summary>
/// If a value exists, apply the mapping function to it, otherwise
/// return an empty Optional
/// </summary>
/// <typeparam name="T"></typeparam>
/// <typeparam name="U"></typeparam>
/// <param name="optional"></param>
/// <param name="mapper"></param>
/// <returns></returns>
If a value exists, apply the mapping function to it, otherwise
return an empty Optional
If a value exists apply the mapping function to it otherwise return an empty Optional
public static Optional<U> Map<T, U>(this Optional<T> optional,
            Func<T, U> mapper)
        {
            if (mapper == null)
            {
                throw new ArgumentNullException(nameof(mapper));
            }
            return optional.IsSome ?
                mapper(optional.Value).ToOptional() :
                Optional<U>.None;
        }
public static Optional < U > Map < T , U > ( this Optional < T > optional , Func < T , U > mapper ) { if ( mapper == null ) { throw new ArgumentNullException ( nameof ( mapper ) ) ; } return optional . IsSome ? mapper ( optional . Value ) . ToOptional ( ) : Optional < U > . None ; }
If a value exists, apply the mapping function to it, otherwise
return an empty Optional
If a value exists apply the mapping function to it otherwise return an empty Optional
None
Optional<T>
this
mapper
Func<T, U>
None
optional
None
typeparam
None
typeparam
None