PutridParrot.Options/OptionExtensions.cs
/// <summary>
/// If the value exists, apply the mapper to it, otherwise
/// return an empty Option.
/// 
/// This is similar to Map except that the mapper returns an Option
/// and if it returns null a NullReferenceException is thrown
/// </summary>
/// <typeparam name="T"></typeparam>
/// <typeparam name="U"></typeparam>
/// <param name="option"></param>
/// <param name="mapper"></param>
/// <returns></returns>
If the value exists, apply the mapper to it, otherwise
return an empty Option.

This is similar to Map except that the mapper returns an Option
and if it returns null a NullReferenceException is thrown
If the value exists apply the mapper to it otherwise return an empty Option . This is similar to Map except that the mapper returns an Option and if it returns null a NullReferenceException is thrown
public static Option<U> Map<T, U>(this Option<T> option,
            Func<T, Option<U>> mapper)
        {
            if (mapper == null)
            {
                throw new ArgumentNullException(nameof(mapper));
            }
            switch (option)
            {
                case Some<T> some:
                    var result = mapper(some.Value);
                    if (result == null)
                    {
                        throw new NullReferenceException("mapper result cannot be null");
                    }
                    return result;
                default:
                    return Option<U>.None;
            }
        }
public static Option < U > Map < T , U > ( this Option < T > option , Func < T , Option < U > > mapper ) { if ( mapper == null ) { throw new ArgumentNullException ( nameof ( mapper ) ) ; } switch ( option ) { case Some < T > some : var result = mapper ( some . Value ) ; if ( result == null ) { throw new NullReferenceException ( " " ) ; } return result ; default : return Option < U > . None ; } }
If the value exists, apply the mapper to it, otherwise
return an empty Option.
If the value exists apply the mapper to it otherwise return an empty Option .
None
Option<T>
this
mapper
Func<T, Option<U>>
None
option
None
typeparam
None
typeparam
None