示例#1
0
        public static void Report()
        {
            var value = Result.Success(1);

            IResult <int> four = value
                                 .Map(Calculator.AddOne)
                                 .Map(Calculator.Square);

            four.Bind(i => CsvFile.TryWriteLine($"The answer is: {i}"));
        }
 /// <summary>
 /// Executes the given function on the disposable type embedded in the extended Result object
 /// </summary>
 /// <typeparam name="TDisposable"></typeparam>
 /// <typeparam name="TResult"></typeparam>
 /// <param name="this"></param>
 /// <param name="functionResult"></param>
 /// <returns></returns>
 public static IResult <TResult> UsingResult <TDisposable, TResult>(this IResult <TDisposable> @this,
                                                                    Func <TDisposable, IResult <TResult> > functionResult) where TDisposable : IDisposable =>
 @this
 .Bind(disposable => disposable.Using(functionResult));
示例#3
0
 public static IResult <L, R2> FlatMap <L, R, R2>(
     this IResult <L, R> self,
     Func <R, IResult <L, R2> > f)
 {
     return(self.Bind(Failure.Create <L, R2>, f));
 }
示例#4
0
 public static IResult <L, R2> Map <L, R, R2>(this IResult <L, R> self, Func <R, R2> f)
 {
     return(self.Bind(Failure.Create <L, R2>, r => Success.Create <L, R2>(f(r))));
 }
示例#5
0
 public void Bind_WhenFirstEndWithFailure() =>
 firstFailureResult.Bind(() => secondResult).Map(_ => throw new Exception("error"), x => x).Message.ShouldBe(error);
示例#6
0
 public void Bind_WhenFirstEndWithSuccess() =>
 firstSuccessResult.Bind(() => secondResult).Map(x => x, _ => throw new Exception("error")).ShouldBe(second);
示例#7
0
 public static IResult <TC, TError> SelectMany <TA, TB, TC, TError>(this IResult <TA, TError> result,
                                                                    Func <TA, IResult <TB, TError> > function, Func <TA, TB, TC> composer) =>
 result.Bind(v1 => function(v1).Select(v2 => composer(v1, v2)));
示例#8
0
 public static IResult <TB, TError> SelectMany <TA, TB, TError>(this IResult <TA, TError> result,
                                                                Func <TA, IResult <TB, TError> > function) => result.Bind(function);
示例#9
0
 public static IResult <TB, TError> MapSuccess <TA, TB, TError>(this IResult <TA, TError> result,
                                                                Func <TA, TB> function) => result.Bind(x => function(x).ToSuccess <TB, TError>());
示例#10
0
 public static IResult <TNext> BindAny <TPrev, TNext>(this IResult <TPrev> prev, Func <TPrev, TNext> next) =>
 prev.Bind(a => next(a).AsResult());
示例#11
0
 public static IResult <Unit> ToUnit <T>(this IResult <T> result) => result.Bind(_ => ResultFactory.CreateSuccess());