예제 #1
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);
 }
예제 #2
0
파일: Option.cs 프로젝트: nmangue/NOption
 /// <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;
예제 #3
0
파일: Option.cs 프로젝트: nmangue/NOption
 /// <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;
예제 #4
0
파일: Option.cs 프로젝트: nmangue/NOption
 /// <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);