ResTFlatMapAsync Method

Overload List

FlatMapAsync(FuncT, TaskRes) (async version) Returns the error when IsErr; map(Unwrap()) when IsOk flattenning the result. Shorthand combining Map and Flatten calls.
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 result = TryGetTeam().FlatMap(TryPutTeam);
// equivalently:
Res result = TryGetTeam().FlatMap(team => TryPutTeam(team));

// this is a shorthand for:
Res result = TryGetTeam()   // Res<Team>
    .Map(TryPutTeam)        // Res<Res>
    .Flatten();             // Res
FlatMapAsyncTOut(FuncT, TaskResTOut) (async version) Returns None when IsNone; map(val) when IsOk flattening the result. Shorthand combining Map and Flatten calls.
C#
static Res<User> TryGetUser() {
    // method that tries to get the user, return Ok(user) or Err.
}
static Res< double> TryGetBalance(User user) {
    // method that tries to get usedr's balance; which might fail, returns:
    // Ok(balance) or Err
}
Res<double> balance = TryGetUser().FlatMap(TryGetBalance);
// equivalent to both below:
var balance = TryGetUser().FlatMap(user => TryGetBalance(user));
var balance = TryGetUser()              // Res<User>
    .Map(user => TryGetBalance(user))   // Res<Res>
    .Flatten();                         // Res

See Also