ResFlatMap(FuncRes) Method

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*/;

Definition

Namespace: Orx.Fun.Result
Assembly: Orx.Fun.Result (in Orx.Fun.Result.dll) Version: 1.3.0+344c8bdd6f720ccfb2d8db7c61b76cf02be18f5f
C#
public Res FlatMap(
	Func<Res> map
)

Parameters

map  FuncRes
Map function to be called lazily to get the final result only if this IsOk.

Return Value

Res

See Also