ResFlatMapAsync Method

Overload List

FlatMapAsync(FuncTaskRes) (async version) Returns the error when IsErr; map() when IsOk, flattenning the result. This is a shorthand for sequential Map and Flatten calls.
C#
// assume we have two methods that can fail; hence returns a Res:
static Res TryRunRiskyOperation() { .. }
static Res TryLogCompletion() { .. }

// we want to call both operations; but the second one only if the first one succeeds.
Res result = TryRunRiskyOperation().FlatMap(TryLogCompletion);
// alternatively:
Res result = TryRunRiskyOperation().FlatMap(() => TryLogCompletion());

// this is equivalent to:
Res result = TryRunRiskyOperation().Map(() => TryLogCompletion()/*Res<Res>*/).Flatten()/*Res*/;
FlatMapAsyncTOut(FuncTaskResTOut) (async version) Returns the error when IsErr; map() when IsOk, flattenning the result. This is a shorthand for sequential Map and Flatten calls.
C#
// assume we have two methods that can fail; hence returns a Res:
static Res TryRunRiskyOperation() { .. }
static Res<int> TryGetCount() { .. }

// we want to call both operations; but the second one only if the first one succeeds.
Res result = TryRunRiskyOperation().FlatMap(TryGetCount);
// alternatively:
Res result = TryRunRiskyOperation().FlatMap(() => TryGetCount());

// this is equivalent to:
Res result = TryRunRiskyOperation().Map(() => TryGetCount()/*Res<Res<int>>*/).Flatten()/*Res<int>*/;

See Also