コード例 #1
0
ファイル: Fallible.g.cs プロジェクト: liuhonglei/Narvalo.NET
 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))));
 }
コード例 #2
0
 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)));
 }
コード例 #3
0
        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)));
        }
コード例 #4
0
 public Fallible <TResult> Gather <TResult>(Fallible <Func <T, TResult> > applicative)
 => IsError && applicative.IsError
     ? Fallible <TResult> .FromError(Error)
     : Fallible <TResult> .η(applicative.Value(Value));
コード例 #5
0
 public Fallible <TResult> Select <TResult>(Func <T, TResult> selector)
 {
     Require.NotNull(selector, nameof(selector));
     return(IsError ? Fallible <TResult> .FromError(Error) : Fallible <TResult> .η(selector(Value)));
 }
コード例 #6
0
 public Fallible <TResult> ReplaceBy <TResult>(TResult other)
 => IsError ? Fallible <TResult> .FromError(Error) : Fallible <TResult> .η(other);
コード例 #7
0
ファイル: Fallible.g.cs プロジェクト: liuhonglei/Narvalo.NET
 /// <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);