public static Fallible <TResult> Select <TSource, TResult>( this Fallible <TSource> @this, Func <TSource, TResult> selector) { /* T4: NotNull(@this) */ Require.NotNull(selector, nameof(selector)); return(@this.Bind(val => Fallible <TResult> .η(selector(val)))); }
public Fallible <TResult> ZipWith <TSecond, TResult>( Fallible <TSecond> second, Func <T, TSecond, TResult> zipper) { Require.NotNull(zipper, nameof(zipper)); return(IsError && second.IsError ? Fallible <TResult> .FromError(Error) : Fallible <TResult> .η(zipper(Value, second.Value))); }
public Fallible <TResult> SelectMany <TMiddle, TResult>( Func <T, Fallible <TMiddle> > selector, Func <T, TMiddle, TResult> resultSelector) { Require.NotNull(selector, nameof(selector)); Require.NotNull(resultSelector, nameof(resultSelector)); if (IsError) { return(Fallible <TResult> .FromError(Error)); } var middle = selector(Value); if (middle.IsError) { return(Fallible <TResult> .FromError(Error)); } return(Fallible <TResult> .η(resultSelector(Value, middle.Value))); }
public Fallible <TResult> Gather <TResult>(Fallible <Func <T, TResult> > applicative) => IsError && applicative.IsError ? Fallible <TResult> .FromError(Error) : Fallible <TResult> .η(applicative.Value(Value));
public Fallible <TResult> Select <TResult>(Func <T, TResult> selector) { Require.NotNull(selector, nameof(selector)); return(IsError ? Fallible <TResult> .FromError(Error) : Fallible <TResult> .η(selector(Value))); }
public Fallible <TResult> ReplaceBy <TResult>(TResult other) => IsError ? Fallible <TResult> .FromError(Error) : Fallible <TResult> .η(other);
/// <summary> /// Obtains an instance of the <see cref="Fallible{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="Fallible{T}"/>.</param> /// <returns>An instance of the <see cref="Fallible{T}"/> class for the specified value.</returns> public static Fallible <T> Of <T>(T value) => Fallible <T> .η(value);