BitwiseOr(ResT, FuncT, ResT) | Limited ahd experimental for now; waiting for generics in operator overloading to be actually useful.
Returns None when IsNone; map(val) when IsOk flattening the result.
Shorthand combining Map and Flatten calls.
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
|
BitwiseOr(ResT, FuncT, Res) | Limited ahd experimental for now; waiting for generics in operator overloading to be actually useful.
Returns the error when IsErr; map(Unwrap()) when IsOk flattenning the result.
Shorthand combining Map and Flatten calls.
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
|