public static async Task ReportAsync() { var value = Result.Success(1); IResult <int> four = await value .Map(Calculator.AddOne) .MapAsync(Calculator.SquareAsync); await four.BindAsync(i => CsvFile.TryWriteLineAsync($"The answer is: {i}")); }
/// <summary> /// /// </summary> /// <typeparam name="TDisposable"></typeparam> /// <typeparam name="TResult"></typeparam> /// <param name="this"></param> /// <param name="functionResultAsync"></param> /// <returns></returns> public static Task <IResult <TResult> > UsingResultAsync <TDisposable, TResult>(this IResult <TDisposable> @this, Func <TDisposable, Task <IResult <TResult> > > functionResultAsync) where TDisposable : IDisposable => @this .BindAsync(disposable => disposable.UsingAsync(functionResultAsync));
public async Task Bind_WhenFirstEndWithSuccessAsync() => (await firstSuccessResult.BindAsync(() => secondResultAsync)).Map(x => x, _ => throw new Exception("error")).ShouldBe(second);
public static Task <IResult <TNext> > BindAnyAsync <TPrev, TNext>(this IResult <TPrev> prev, Func <TPrev, Task <TNext> > next) => prev.BindAsync(a => next(a).AsResultAsync());