Class ResultSwitchExtensions
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
resultResultThe result to dispatch.
onSuccessActionAction to execute on success.
onFailureAction<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
resultResultThe result to dispatch.
onSuccessFunc<Task>Async action to execute on success.
onFailureFunc<ImmutableList<IError>, Task>Async action to execute on failure with errors.
cancellationTokenCancellationTokenOptional 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
resultResult<T>The result to dispatch.
onSuccessFunc<T, Task>Async action to execute on success with value.
onFailureFunc<ImmutableList<IError>, Task>Async action to execute on failure with errors.
cancellationTokenCancellationTokenOptional cancellation token.
Returns
- Task
A task representing the async operation.
Type Parameters
TThe 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
resultResult<T>The result to dispatch.
onSuccessAction<T>Action to execute on success with value.
onFailureAction<ImmutableList<IError>>Action to execute on failure with errors.
Type Parameters
TThe value type.