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)))); }
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))); }
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))); }
/// <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);
public Outcome <TResult> Gather <TResult>(Outcome <Func <T, TResult> > applicative) => IsError && applicative.IsError ? Outcome <TResult> .FromError(Error) : Outcome <TResult> .η(applicative.Value(Value));
public Outcome <TResult> Select <TResult>(Func <T, TResult> selector) { Require.NotNull(selector, nameof(selector)); return(IsError ? Outcome <TResult> .FromError(Error) : Outcome <TResult> .η(selector(Value))); }
public Outcome <TResult> ReplaceBy <TResult>(TResult other) => IsError ? Outcome <TResult> .FromError(Error) : Outcome <TResult> .η(other);