示例#1
0
 public static Outcome <TResult> Select <TSource, TResult>(
     this Outcome <TSource> @this,
     Func <TSource, TResult> selector)
 {
     /* T4: NotNull(@this) */
     Require.NotNull(selector, nameof(selector));
     return(@this.Bind(val => Outcome <TResult> .η(selector(val))));
 }
示例#2
0
 public Outcome <TResult> ZipWith <TSecond, TResult>(
     Outcome <TSecond> second,
     Func <T, TSecond, TResult> zipper)
 {
     Require.NotNull(zipper, nameof(zipper));
     return(IsError && second.IsError
         ? Outcome <TResult> .FromError(Error)
         : Outcome <TResult> .η(zipper(Value, second.Value)));
 }
示例#3
0
        public Outcome <TResult> SelectMany <TMiddle, TResult>(
            Func <T, Outcome <TMiddle> > selector,
            Func <T, TMiddle, TResult> resultSelector)
        {
            Require.NotNull(selector, nameof(selector));
            Require.NotNull(resultSelector, nameof(resultSelector));

            if (IsError)
            {
                return(Outcome <TResult> .FromError(Error));
            }
            var middle = selector(Value);

            if (middle.IsError)
            {
                return(Outcome <TResult> .FromError(Error));
            }
            return(Outcome <TResult> .η(resultSelector(Value, middle.Value)));
        }
示例#4
0
 /// <summary>
 /// Obtains an instance of the <see cref="Outcome{T}"/> class for the specified value.
 /// </summary>
 /// <typeparam name="T">The underlying type of <paramref name="value"/>.</typeparam>
 /// <param name="value">A value to be wrapped into an object of type <see cref="Outcome{T}"/>.</param>
 /// <returns>An instance of the <see cref="Outcome{T}"/> class for the specified value.</returns>
 public static Outcome <T> Of <T>(T value) => Outcome <T> .η(value);
示例#5
0
 public Outcome <TResult> Gather <TResult>(Outcome <Func <T, TResult> > applicative)
 => IsError && applicative.IsError
     ? Outcome <TResult> .FromError(Error)
     : Outcome <TResult> .η(applicative.Value(Value));
示例#6
0
 public Outcome <TResult> Select <TResult>(Func <T, TResult> selector)
 {
     Require.NotNull(selector, nameof(selector));
     return(IsError ? Outcome <TResult> .FromError(Error) : Outcome <TResult> .η(selector(Value)));
 }
示例#7
0
 public Outcome <TResult> ReplaceBy <TResult>(TResult other)
 => IsError ? Outcome <TResult> .FromError(Error) : Outcome <TResult> .η(other);