Class ResultMatchExtensions

Namespace
REslava.Result
Assembly
REslava.Result.dll

Extension methods for match operations on Result types.

public static class ResultMatchExtensions
Inheritance
ResultMatchExtensions
Inherited Members

Methods

Match(Result, Action, Action<ImmutableList<IError>>)

Executes one of two actions based on success or failure.

public static void Match(this Result result, Action onSuccess, Action<ImmutableList<IError>> onFailure)

Parameters

result Result

The result to match.

onSuccess Action

Action to execute on success.

onFailure Action<ImmutableList<IError>>

Action to execute on failure with errors.

MatchAsync(Result, Func<Task>, Func<ImmutableList<IError>, Task>, CancellationToken)

Asynchronously executes one of two async actions based on success or failure.

public static Task MatchAsync(this Result result, Func<Task> onSuccess, Func<ImmutableList<IError>, Task> onFailure, CancellationToken cancellationToken = default)

Parameters

result Result

The result to match.

onSuccess Func<Task>

Async action to execute on success.

onFailure Func<ImmutableList<IError>, Task>

Async action to execute on failure with errors.

cancellationToken CancellationToken

Optional cancellation token.

Returns

Task

A task representing the async operation.

MatchAsync<TOut>(Result, Func<Task<TOut>>, Func<ImmutableList<IError>, Task<TOut>>, CancellationToken)

Asynchronously matches result to one of two async functions based on success or failure.

public static Task<TOut> MatchAsync<TOut>(this Result result, Func<Task<TOut>> onSuccess, Func<ImmutableList<IError>, Task<TOut>> onFailure, CancellationToken cancellationToken = default)

Parameters

result Result

The result to match.

onSuccess Func<Task<TOut>>

Async function to execute on success.

onFailure Func<ImmutableList<IError>, Task<TOut>>

Async function to execute on failure with errors.

cancellationToken CancellationToken

Optional cancellation token.

Returns

Task<TOut>

A task containing the result of the executed function.

Type Parameters

TOut

The return type.

MatchAsync<T>(Result<T>, Func<T, Task>, Func<ImmutableList<IError>, Task>, CancellationToken)

Asynchronously executes one of two async actions based on success or failure.

public static Task MatchAsync<T>(this Result<T> result, Func<T, Task> onSuccess, Func<ImmutableList<IError>, Task> onFailure, CancellationToken cancellationToken = default)

Parameters

result Result<T>

The result to match.

onSuccess Func<T, Task>

Async action to execute on success with value.

onFailure Func<ImmutableList<IError>, Task>

Async action to execute on failure with errors.

cancellationToken CancellationToken

Optional cancellation token.

Returns

Task

A task representing the async operation.

Type Parameters

T

The value type.

MatchAsync<T, TOut>(Result<T>, Func<T, Task<TOut>>, Func<ImmutableList<IError>, Task<TOut>>, CancellationToken)

Asynchronously matches result to one of two async functions based on success or failure.

public static Task<TOut> MatchAsync<T, TOut>(this Result<T> result, Func<T, Task<TOut>> onSuccess, Func<ImmutableList<IError>, Task<TOut>> onFailure, CancellationToken cancellationToken = default)

Parameters

result Result<T>

The result to match.

onSuccess Func<T, Task<TOut>>

Async function to execute on success with value.

onFailure Func<ImmutableList<IError>, Task<TOut>>

Async function to execute on failure with errors.

cancellationToken CancellationToken

Optional cancellation token.

Returns

Task<TOut>

A task containing the result of the executed function.

Type Parameters

T

The value type.

TOut

The return type.

Match<TOut>(Result, Func<TOut>, Func<ImmutableList<IError>, TOut>)

Matches result to one of two functions based on success or failure.

public static TOut Match<TOut>(this Result result, Func<TOut> onSuccess, Func<ImmutableList<IError>, TOut> onFailure)

Parameters

result Result

The result to match.

onSuccess Func<TOut>

Function to execute on success.

onFailure Func<ImmutableList<IError>, TOut>

Function to execute on failure with errors.

Returns

TOut

The result of the executed function.

Type Parameters

TOut

The return type.

Match<T>(Result<T>, Action<T>, Action<ImmutableList<IError>>)

Executes one of two actions based on success or failure.

public static void Match<T>(this Result<T> result, Action<T> onSuccess, Action<ImmutableList<IError>> onFailure)

Parameters

result Result<T>

The result to match.

onSuccess Action<T>

Action to execute on success with value.

onFailure Action<ImmutableList<IError>>

Action to execute on failure with errors.

Type Parameters

T

The value type.

Match<T, TOut>(Result<T>, Func<T, TOut>, Func<ImmutableList<IError>, TOut>)

Matches result to one of two functions based on success or failure.

public static TOut Match<T, TOut>(this Result<T> result, Func<T, TOut> onSuccess, Func<ImmutableList<IError>, TOut> onFailure)

Parameters

result Result<T>

The result to match.

onSuccess Func<T, TOut>

Function to execute on success with value.

onFailure Func<ImmutableList<IError>, TOut>

Function to execute on failure with errors.

Returns

TOut

The result of the executed function.

Type Parameters

T

The value type.

TOut

The return type.