Class ResultSwitchExtensions

Namespace
REslava.Result
Assembly
REslava.Result.dll

Extension methods for void side-effect dispatch on Result types.

public static class ResultSwitchExtensions
Inheritance
ResultSwitchExtensions
Inherited Members

Methods

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

Executes one of two actions based on success or failure.

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

Parameters

result Result

The result to dispatch.

onSuccess Action

Action to execute on success.

onFailure Action<ImmutableList<IError>>

Action to execute on failure with errors.

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

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

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

Parameters

result Result

The result to dispatch.

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.

SwitchAsync<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 SwitchAsync<T>(this Result<T> result, Func<T, Task> onSuccess, Func<ImmutableList<IError>, Task> onFailure, CancellationToken cancellationToken = default)

Parameters

result Result<T>

The result to dispatch.

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.

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

Executes one of two actions based on success or failure.

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

Parameters

result Result<T>

The result to dispatch.

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.