ResTTryFlatMapAsyncTOut Method

(async version) Returns the error when IsErr. Otherwise, tries to return map(val) in a try-catch block and returns the Err if it throws.
C#
static Res<User> TryGetUser() { .. }
static Res<long> PutUserToDbGetId(User user) {
    // method that writes the user to a database table and returns back the auto-generated id/primary-key
    // might throw in cases of connection errors!
}

Res<long> id = TryGetUser().TryFlatMap(PutUserToDbGetId);
// equivalently:
Res<long> id = TryGetUser().TryFlatMap(user => PutUserToDbGetId(user));
// Res<long> id will be:
// - Err(called on Err) when TryGetUser returns Err,
// - Err(relevant error message) when TryGetUser returns Ok(user) but PutUserToDbGetId returns an Err,
// - Err(relevant error message) when TryGetUser returns Ok(user) but the database transaction throws an exception,
// - Ok(id) when TryGetUser returns Ok(user), the database transaction succeeds and returns the auto-generated id.

Definition

Namespace: Orx.Fun.Result
Assembly: Orx.Fun.Result (in Orx.Fun.Result.dll) Version: 1.3.0+344c8bdd6f720ccfb2d8db7c61b76cf02be18f5f
C#
public Task<Res<TOut>> TryFlatMapAsync<TOut>(
	Func<T, Task<Res<TOut>>> map,
	string name = ""
)

Parameters

map  FuncT, TaskResTOut
Function (T -> Res<TOut>) to be called in try-catch block to get the result when Ok; will not be called when Err.
name  String  (Optional)
Name of the map function/operation; to be appended to the error messages if the function throws. Omitting the argument will automatically be filled with the function's expression in the caller side.

Type Parameters

TOut

[Missing <typeparam name="TOut"/> documentation for "M:Orx.Fun.Result.Res`1.TryFlatMapAsync``1(System.Func{`0,System.Threading.Tasks.Task{Orx.Fun.Result.Res{``0}}},System.String)"]

Return Value

TaskResTOut

See Also