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