Пример #1
0
        public bool Equals(OptionImpl <T> other)
        {
            if (_hasSome && other._hasSome)
            {
                return(EqualityComparer <T> .Default.Equals(_value, other._value));
            }

            return(!_hasSome && !other._hasSome);
        }
Пример #2
0
 /// <summary>
 /// Projects the option value into a new form.
 /// </summary>
 /// <typeparam name="TResult">The type of the value returned by <paramref name="map"/>.</typeparam>
 /// <param name="map">A transform function to apply to the option value.</param>
 /// <returns>The result of invoking the transform function with the option value, if any; otherwhise <c>None</c></returns>
 public Option <TResult> Map <TResult>(Func <T, TResult> map)
 {
     return(_hasSome ? OptionImpl <TResult> .Some(map(_value)) : OptionImpl <TResult> .None);
 }
Пример #3
0
 /// <summary>
 /// Wraps the specified value in an instance of <see cref="Option{T}"/> if <paramref name="when"/> is <c>true</c>.
 /// </summary>
 /// <param name="value">The value to be wrapped in an option. (Can be <c>null</c>)</param>
 /// <param name="when">Indicates whether the result should be something or none. (Can be <c>null</c>)</param>
 /// <returns>An option wrapping the value.</returns>
 public static Option <T> Some <T>(T obj, bool when) => when ? OptionImpl <T> .Some(obj) : OptionImpl <T> .None;
Пример #4
0
 /// <summary>
 /// Wraps the specified value in an instance of <see cref="Option{T}"/> if <paramref name="value"/> is not null.
 /// </summary>
 /// <param name="value">The value to be wrapped in an option. (Can be <c>null</c>)</param>
 /// <returns>An option wrapping the value.</returns>
 public static Option <T> SomeIfNotNull <T>(T value) where T : class => value != null ? OptionImpl <T> .Some(value) : OptionImpl <T> .None;
Пример #5
0
 /// <summary>
 /// Wraps the specified value in an instance of <see cref="Option{T}"/>.
 /// </summary>
 /// <param name="value">The value to be wrapped in an option. (Can be <c>null</c>)</param>
 /// <returns>An option wrapping the value.</returns>
 public static Option <T> Some <T>(T value) => OptionImpl <T> .Some(value);