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

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