ResTFlatMapBackAsync Method

(async version) Returns the error when IsErr; map(Unwrap()).Map(() => this) when IsOk flattenning the result. Shorthand combining Map, Flatten and Map calls.

Note that the difference of FlatMapBack(FuncT, Res) from FlatMap(FuncT, Res) is in the return type; returns Res<T> rather than Res.

It appends back the original value to the result if the result was and is Ok after the map call.

C#
static Res<Team> TryGetTeam() { .. } // tries to grab a team; might fail, hence, returns Res.
static Res TryPutTeam(Team team) { .. } // tries to put the team; might fail, hence, returns Res.

Res<Team> result = TryGetTeam().FlatMapBack(TryPutTeam);
// equivalently:
Res<Team> result = TryGetTeam().FlatMapBack(team => TryPutTeam(team));

// this is a shorthand for:
Res<Team> result = TryGetTeam()                               // Res<Team>
    .FlatMap(team => TryPutTeam(team).Map(() => team)); // Res<Team>

Definition

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

Parameters

map  FuncT, TaskRes
Function (T -> Res) that maps the underlying value to a Res when IsOk.

Return Value

TaskResT

See Also