Table of Contents

Class MatchTupleExtensionsAsync

Namespace
Trellis
Assembly
Trellis.Core.dll

Provides asynchronous pattern matching extension methods for Result types containing tuples (2-5 elements). Supports both Task and ValueTask for async pattern matching.

public static class MatchTupleExtensionsAsync
Inheritance
MatchTupleExtensionsAsync
Inherited Members

Examples

var ct = cancellationToken;
var response = await GetUserDataAsync(userId)
    .MatchAsync(
        onSuccess: (email, name) => CreateUserAsync(email, name, ct),
        onFailure: error => LogErrorAsync(error, ct)
    );

Remarks

These methods handle various async scenarios with automatic tuple destructuring. Users should capture CancellationToken in their lambda closures when cancellation support is needed.

All variants automatically destructure tuple values for clean, readable async code.

Methods

MatchAsync<T1, T2, TOut>(Task<Result<(T1, T2)>>, Func<T1, T2, Task<TOut>>, Func<Error, Task<TOut>>)

Asynchronously matches on a Result containing a 2-element tuple with async handlers, destructuring the tuple values.

public static Task<TOut> MatchAsync<T1, T2, TOut>(this Task<Result<(T1, T2)>> resultTask, Func<T1, T2, Task<TOut>> onSuccess, Func<Error, Task<TOut>> onFailure)

Parameters

resultTask Task<Result<(T1, T2)>>

The task representing the result to match on.

onSuccess Func<T1, T2, Task<TOut>>

Async function to execute on success, receiving 2 destructured tuple values.

onFailure Func<Error, Task<TOut>>

Async function to execute on failure.

Returns

Task<TOut>

A task that represents the asynchronous operation containing the output from either function.

Type Parameters

T1

The type of the first tuple element.

T2

The type of the second tuple element.

TOut

The type of the output.

MatchAsync<T1, T2, TOut>(Task<Result<(T1, T2)>>, Func<T1, T2, TOut>, Func<Error, TOut>)

Asynchronously matches on a Result containing a 2-element tuple with synchronous handlers, destructuring the tuple values.

public static Task<TOut> MatchAsync<T1, T2, TOut>(this Task<Result<(T1, T2)>> resultTask, Func<T1, T2, TOut> onSuccess, Func<Error, TOut> onFailure)

Parameters

resultTask Task<Result<(T1, T2)>>

The task representing the result to match on.

onSuccess Func<T1, T2, TOut>

Function to execute on success, receiving 2 destructured tuple values.

onFailure Func<Error, TOut>

Function to execute on failure.

Returns

Task<TOut>

A task that represents the asynchronous operation containing the output from either function.

Type Parameters

T1

The type of the first tuple element.

T2

The type of the second tuple element.

TOut

The type of the output.

MatchAsync<T1, T2, TOut>(Result<(T1, T2)>, Func<T1, T2, Task<TOut>>, Func<Error, Task<TOut>>)

Matches on a Result containing a 2-element tuple with asynchronous handlers, destructuring the tuple values.

public static Task<TOut> MatchAsync<T1, T2, TOut>(this Result<(T1, T2)> result, Func<T1, T2, Task<TOut>> onSuccess, Func<Error, Task<TOut>> onFailure)

Parameters

result Result<(T1, T2)>

The result to match on.

onSuccess Func<T1, T2, Task<TOut>>

Async function to execute on success, receiving 2 destructured tuple values.

onFailure Func<Error, Task<TOut>>

Async function to execute on failure.

Returns

Task<TOut>

A task that represents the asynchronous operation containing the output from either function.

Type Parameters

T1

The type of the first tuple element.

T2

The type of the second tuple element.

TOut

The type of the output.

MatchAsync<T1, T2, T3, TOut>(Task<Result<(T1, T2, T3)>>, Func<T1, T2, T3, Task<TOut>>, Func<Error, Task<TOut>>)

Asynchronously matches on a Result containing a 3-element tuple with async handlers, destructuring the tuple values.

public static Task<TOut> MatchAsync<T1, T2, T3, TOut>(this Task<Result<(T1, T2, T3)>> resultTask, Func<T1, T2, T3, Task<TOut>> onSuccess, Func<Error, Task<TOut>> onFailure)

Parameters

resultTask Task<Result<(T1, T2, T3)>>

The task representing the result to match on.

onSuccess Func<T1, T2, T3, Task<TOut>>

Async function to execute on success, receiving 3 destructured tuple values.

onFailure Func<Error, Task<TOut>>

Async function to execute on failure.

Returns

Task<TOut>

A task that represents the asynchronous operation containing the output from either function.

Type Parameters

T1

The type of the first tuple element.

T2

The type of the second tuple element.

T3

The type of the third tuple element.

TOut

The type of the output.

MatchAsync<T1, T2, T3, TOut>(Task<Result<(T1, T2, T3)>>, Func<T1, T2, T3, TOut>, Func<Error, TOut>)

Asynchronously matches on a Result containing a 3-element tuple with synchronous handlers, destructuring the tuple values.

public static Task<TOut> MatchAsync<T1, T2, T3, TOut>(this Task<Result<(T1, T2, T3)>> resultTask, Func<T1, T2, T3, TOut> onSuccess, Func<Error, TOut> onFailure)

Parameters

resultTask Task<Result<(T1, T2, T3)>>

The task representing the result to match on.

onSuccess Func<T1, T2, T3, TOut>

Function to execute on success, receiving 3 destructured tuple values.

onFailure Func<Error, TOut>

Function to execute on failure.

Returns

Task<TOut>

A task that represents the asynchronous operation containing the output from either function.

Type Parameters

T1

The type of the first tuple element.

T2

The type of the second tuple element.

T3

The type of the third tuple element.

TOut

The type of the output.

MatchAsync<T1, T2, T3, TOut>(Result<(T1, T2, T3)>, Func<T1, T2, T3, Task<TOut>>, Func<Error, Task<TOut>>)

Matches on a Result containing a 3-element tuple with asynchronous handlers, destructuring the tuple values.

public static Task<TOut> MatchAsync<T1, T2, T3, TOut>(this Result<(T1, T2, T3)> result, Func<T1, T2, T3, Task<TOut>> onSuccess, Func<Error, Task<TOut>> onFailure)

Parameters

result Result<(T1, T2, T3)>

The result to match on.

onSuccess Func<T1, T2, T3, Task<TOut>>

Async function to execute on success, receiving 3 destructured tuple values.

onFailure Func<Error, Task<TOut>>

Async function to execute on failure.

Returns

Task<TOut>

A task that represents the asynchronous operation containing the output from either function.

Type Parameters

T1

The type of the first tuple element.

T2

The type of the second tuple element.

T3

The type of the third tuple element.

TOut

The type of the output.

MatchAsync<T1, T2, T3, T4, TOut>(Task<Result<(T1, T2, T3, T4)>>, Func<T1, T2, T3, T4, Task<TOut>>, Func<Error, Task<TOut>>)

Asynchronously matches on a Result containing a 4-element tuple with async handlers, destructuring the tuple values.

public static Task<TOut> MatchAsync<T1, T2, T3, T4, TOut>(this Task<Result<(T1, T2, T3, T4)>> resultTask, Func<T1, T2, T3, T4, Task<TOut>> onSuccess, Func<Error, Task<TOut>> onFailure)

Parameters

resultTask Task<Result<(T1, T2, T3, T4)>>

The task representing the result to match on.

onSuccess Func<T1, T2, T3, T4, Task<TOut>>

Async function to execute on success, receiving 4 destructured tuple values.

onFailure Func<Error, Task<TOut>>

Async function to execute on failure.

Returns

Task<TOut>

A task that represents the asynchronous operation containing the output from either function.

Type Parameters

T1

The type of the first tuple element.

T2

The type of the second tuple element.

T3

The type of the third tuple element.

T4

The type of the fourth tuple element.

TOut

The type of the output.

MatchAsync<T1, T2, T3, T4, TOut>(Task<Result<(T1, T2, T3, T4)>>, Func<T1, T2, T3, T4, TOut>, Func<Error, TOut>)

Asynchronously matches on a Result containing a 4-element tuple with synchronous handlers, destructuring the tuple values.

public static Task<TOut> MatchAsync<T1, T2, T3, T4, TOut>(this Task<Result<(T1, T2, T3, T4)>> resultTask, Func<T1, T2, T3, T4, TOut> onSuccess, Func<Error, TOut> onFailure)

Parameters

resultTask Task<Result<(T1, T2, T3, T4)>>

The task representing the result to match on.

onSuccess Func<T1, T2, T3, T4, TOut>

Function to execute on success, receiving 4 destructured tuple values.

onFailure Func<Error, TOut>

Function to execute on failure.

Returns

Task<TOut>

A task that represents the asynchronous operation containing the output from either function.

Type Parameters

T1

The type of the first tuple element.

T2

The type of the second tuple element.

T3

The type of the third tuple element.

T4

The type of the fourth tuple element.

TOut

The type of the output.

MatchAsync<T1, T2, T3, T4, TOut>(Result<(T1, T2, T3, T4)>, Func<T1, T2, T3, T4, Task<TOut>>, Func<Error, Task<TOut>>)

Matches on a Result containing a 4-element tuple with asynchronous handlers, destructuring the tuple values.

public static Task<TOut> MatchAsync<T1, T2, T3, T4, TOut>(this Result<(T1, T2, T3, T4)> result, Func<T1, T2, T3, T4, Task<TOut>> onSuccess, Func<Error, Task<TOut>> onFailure)

Parameters

result Result<(T1, T2, T3, T4)>

The result to match on.

onSuccess Func<T1, T2, T3, T4, Task<TOut>>

Async function to execute on success, receiving 4 destructured tuple values.

onFailure Func<Error, Task<TOut>>

Async function to execute on failure.

Returns

Task<TOut>

A task that represents the asynchronous operation containing the output from either function.

Type Parameters

T1

The type of the first tuple element.

T2

The type of the second tuple element.

T3

The type of the third tuple element.

T4

The type of the fourth tuple element.

TOut

The type of the output.

MatchAsync<T1, T2, T3, T4, T5, TOut>(Task<Result<(T1, T2, T3, T4, T5)>>, Func<T1, T2, T3, T4, T5, Task<TOut>>, Func<Error, Task<TOut>>)

Asynchronously matches on a Result containing a 5-element tuple with async handlers, destructuring the tuple values.

public static Task<TOut> MatchAsync<T1, T2, T3, T4, T5, TOut>(this Task<Result<(T1, T2, T3, T4, T5)>> resultTask, Func<T1, T2, T3, T4, T5, Task<TOut>> onSuccess, Func<Error, Task<TOut>> onFailure)

Parameters

resultTask Task<Result<(T1, T2, T3, T4, T5)>>

The task representing the result to match on.

onSuccess Func<T1, T2, T3, T4, T5, Task<TOut>>

Async function to execute on success, receiving 5 destructured tuple values.

onFailure Func<Error, Task<TOut>>

Async function to execute on failure.

Returns

Task<TOut>

A task that represents the asynchronous operation containing the output from either function.

Type Parameters

T1

The type of the first tuple element.

T2

The type of the second tuple element.

T3

The type of the third tuple element.

T4

The type of the fourth tuple element.

T5

The type of the fifth tuple element.

TOut

The type of the output.

MatchAsync<T1, T2, T3, T4, T5, TOut>(Task<Result<(T1, T2, T3, T4, T5)>>, Func<T1, T2, T3, T4, T5, TOut>, Func<Error, TOut>)

Asynchronously matches on a Result containing a 5-element tuple with synchronous handlers, destructuring the tuple values.

public static Task<TOut> MatchAsync<T1, T2, T3, T4, T5, TOut>(this Task<Result<(T1, T2, T3, T4, T5)>> resultTask, Func<T1, T2, T3, T4, T5, TOut> onSuccess, Func<Error, TOut> onFailure)

Parameters

resultTask Task<Result<(T1, T2, T3, T4, T5)>>

The task representing the result to match on.

onSuccess Func<T1, T2, T3, T4, T5, TOut>

Function to execute on success, receiving 5 destructured tuple values.

onFailure Func<Error, TOut>

Function to execute on failure.

Returns

Task<TOut>

A task that represents the asynchronous operation containing the output from either function.

Type Parameters

T1

The type of the first tuple element.

T2

The type of the second tuple element.

T3

The type of the third tuple element.

T4

The type of the fourth tuple element.

T5

The type of the fifth tuple element.

TOut

The type of the output.

MatchAsync<T1, T2, T3, T4, T5, TOut>(Result<(T1, T2, T3, T4, T5)>, Func<T1, T2, T3, T4, T5, Task<TOut>>, Func<Error, Task<TOut>>)

Matches on a Result containing a 5-element tuple with asynchronous handlers, destructuring the tuple values.

public static Task<TOut> MatchAsync<T1, T2, T3, T4, T5, TOut>(this Result<(T1, T2, T3, T4, T5)> result, Func<T1, T2, T3, T4, T5, Task<TOut>> onSuccess, Func<Error, Task<TOut>> onFailure)

Parameters

result Result<(T1, T2, T3, T4, T5)>

The result to match on.

onSuccess Func<T1, T2, T3, T4, T5, Task<TOut>>

Async function to execute on success, receiving 5 destructured tuple values.

onFailure Func<Error, Task<TOut>>

Async function to execute on failure.

Returns

Task<TOut>

A task that represents the asynchronous operation containing the output from either function.

Type Parameters

T1

The type of the first tuple element.

T2

The type of the second tuple element.

T3

The type of the third tuple element.

T4

The type of the fourth tuple element.

T5

The type of the fifth tuple element.

TOut

The type of the output.

SwitchAsync<T1, T2>(Task<Result<(T1, T2)>>, Func<T1, T2, Task>, Func<Error, Task>)

Asynchronously switches on a Result containing a 2-element tuple for side effects, destructuring the tuple values.

public static Task SwitchAsync<T1, T2>(this Task<Result<(T1, T2)>> resultTask, Func<T1, T2, Task> onSuccess, Func<Error, Task> onFailure)

Parameters

resultTask Task<Result<(T1, T2)>>

The task representing the result to switch on.

onSuccess Func<T1, T2, Task>

Async action to execute on success, receiving 2 destructured tuple values.

onFailure Func<Error, Task>

Async action to execute on failure, receiving the error.

Returns

Task

A task that represents the asynchronous operation.

Type Parameters

T1

The type of the first tuple element.

T2

The type of the second tuple element.

Remarks

Use SwitchAsync for side effects (logging, notifications) without returning a value.

SwitchAsync<T1, T2, T3>(Task<Result<(T1, T2, T3)>>, Func<T1, T2, T3, Task>, Func<Error, Task>)

Asynchronously switches on a Result containing a 3-element tuple for side effects, destructuring the tuple values.

public static Task SwitchAsync<T1, T2, T3>(this Task<Result<(T1, T2, T3)>> resultTask, Func<T1, T2, T3, Task> onSuccess, Func<Error, Task> onFailure)

Parameters

resultTask Task<Result<(T1, T2, T3)>>

The task representing the result to switch on.

onSuccess Func<T1, T2, T3, Task>

Async action to execute on success, receiving 3 destructured tuple values.

onFailure Func<Error, Task>

Async action to execute on failure, receiving the error.

Returns

Task

A task that represents the asynchronous operation.

Type Parameters

T1

The type of the first tuple element.

T2

The type of the second tuple element.

T3

The type of the third tuple element.

Remarks

Use SwitchAsync for side effects (logging, notifications) without returning a value.

SwitchAsync<T1, T2, T3, T4>(Task<Result<(T1, T2, T3, T4)>>, Func<T1, T2, T3, T4, Task>, Func<Error, Task>)

Asynchronously switches on a Result containing a 4-element tuple for side effects, destructuring the tuple values.

public static Task SwitchAsync<T1, T2, T3, T4>(this Task<Result<(T1, T2, T3, T4)>> resultTask, Func<T1, T2, T3, T4, Task> onSuccess, Func<Error, Task> onFailure)

Parameters

resultTask Task<Result<(T1, T2, T3, T4)>>

The task representing the result to switch on.

onSuccess Func<T1, T2, T3, T4, Task>

Async action to execute on success, receiving 4 destructured tuple values.

onFailure Func<Error, Task>

Async action to execute on failure, receiving the error.

Returns

Task

A task that represents the asynchronous operation.

Type Parameters

T1

The type of the first tuple element.

T2

The type of the second tuple element.

T3

The type of the third tuple element.

T4

The type of the fourth tuple element.

Remarks

Use SwitchAsync for side effects (logging, notifications) without returning a value.

SwitchAsync<T1, T2, T3, T4, T5>(Task<Result<(T1, T2, T3, T4, T5)>>, Func<T1, T2, T3, T4, T5, Task>, Func<Error, Task>)

Asynchronously switches on a Result containing a 5-element tuple for side effects, destructuring the tuple values.

public static Task SwitchAsync<T1, T2, T3, T4, T5>(this Task<Result<(T1, T2, T3, T4, T5)>> resultTask, Func<T1, T2, T3, T4, T5, Task> onSuccess, Func<Error, Task> onFailure)

Parameters

resultTask Task<Result<(T1, T2, T3, T4, T5)>>

The task representing the result to switch on.

onSuccess Func<T1, T2, T3, T4, T5, Task>

Async action to execute on success, receiving 5 destructured tuple values.

onFailure Func<Error, Task>

Async action to execute on failure, receiving the error.

Returns

Task

A task that represents the asynchronous operation.

Type Parameters

T1

The type of the first tuple element.

T2

The type of the second tuple element.

T3

The type of the third tuple element.

T4

The type of the fourth tuple element.

T5

The type of the fifth tuple element.

Remarks

Use SwitchAsync for side effects (logging, notifications) without returning a value.