Class ResultExtensions
- Namespace
- Compendium.Core.Results
- Assembly
- Compendium.Core.dll
Extension methods for the Result types providing functional programming patterns.
public static class ResultExtensions
- Inheritance
-
ResultExtensions
- Inherited Members
Methods
BindAsync<TValue, TNewValue>(Task<Result<TValue>>, Func<TValue, Task<Result<TNewValue>>>)
Asynchronously binds the result to a new result-returning function.
public static Task<Result<TNewValue>> BindAsync<TValue, TNewValue>(this Task<Result<TValue>> resultTask, Func<TValue, Task<Result<TNewValue>>> binder)
Parameters
resultTaskTask<Result<TValue>>The result task.
binderFunc<TValue, Task<Result<TNewValue>>>The binding function.
Returns
Type Parameters
TValueThe type of the original value.
TNewValueThe type of the new value.
Bind<TValue, TNewValue>(Result<TValue>, Func<TValue, Result<TNewValue>>)
Binds the result to a new result-returning function.
public static Result<TNewValue> Bind<TValue, TNewValue>(this Result<TValue> result, Func<TValue, Result<TNewValue>> binder)
Parameters
Returns
- Result<TNewValue>
The result of the binding function if successful; otherwise, the original error.
Type Parameters
TValueThe type of the original value.
TNewValueThe type of the new value.
MapAsync<TValue, TNewValue>(Task<Result<TValue>>, Func<TValue, TNewValue>)
Asynchronously maps the value of a successful result to a new value.
public static Task<Result<TNewValue>> MapAsync<TValue, TNewValue>(this Task<Result<TValue>> resultTask, Func<TValue, TNewValue> mapper)
Parameters
resultTaskTask<Result<TValue>>The result task.
mapperFunc<TValue, TNewValue>The mapping function.
Returns
Type Parameters
TValueThe type of the original value.
TNewValueThe type of the new value.
Map<TValue>(Result, TValue)
Converts a Result to a Result<TValue>.
public static Result<TValue> Map<TValue>(this Result result, TValue value)
Parameters
resultResultThe result.
valueTValueThe value to use if the result is successful.
Returns
- Result<TValue>
A Result<TValue> with the specified value if successful; otherwise, the original error.
Type Parameters
TValueThe type of the value.
Map<TValue, TNewValue>(Result<TValue>, Func<TValue, TNewValue>)
Maps the value of a successful result to a new value.
public static Result<TNewValue> Map<TValue, TNewValue>(this Result<TValue> result, Func<TValue, TNewValue> mapper)
Parameters
Returns
- Result<TNewValue>
A new result with the mapped value if successful; otherwise, the original error.
Type Parameters
TValueThe type of the original value.
TNewValueThe type of the new value.
Match<TValue>(Result<TValue>, Action<TValue>, Action<Error>)
Matches the result and executes the appropriate action.
public static void Match<TValue>(this Result<TValue> result, Action<TValue> onSuccess, Action<Error> onFailure)
Parameters
resultResult<TValue>The result.
onSuccessAction<TValue>The action to execute on success.
onFailureAction<Error>The action to execute on failure.
Type Parameters
TValueThe type of the value.
Match<TValue, TResult>(Result<TValue>, Func<TValue, TResult>, Func<Error, TResult>)
Matches the result and executes the appropriate function.
public static TResult Match<TValue, TResult>(this Result<TValue> result, Func<TValue, TResult> onSuccess, Func<Error, TResult> onFailure)
Parameters
resultResult<TValue>The result.
onSuccessFunc<TValue, TResult>The function to execute on success.
onFailureFunc<Error, TResult>The function to execute on failure.
Returns
- TResult
The result of the executed function.
Type Parameters
TValueThe type of the value.
TResultThe type of the result.
TapAsync<TValue>(Task<Result<TValue>>, Func<TValue, Task>)
Asynchronously executes a function if the result is successful.
public static Task<Result<TValue>> TapAsync<TValue>(this Task<Result<TValue>> resultTask, Func<TValue, Task> onSuccess)
Parameters
resultTaskTask<Result<TValue>>The result task.
onSuccessFunc<TValue, Task>The function to execute on success.
Returns
Type Parameters
TValueThe type of the value.
TapError<TValue>(Result<TValue>, Action<Error>)
Executes a function if the result is failed.
public static Result<TValue> TapError<TValue>(this Result<TValue> result, Action<Error> onFailure)
Parameters
Returns
- Result<TValue>
The original result.
Type Parameters
TValueThe type of the value.
Tap<TValue>(Result<TValue>, Action<TValue>)
Executes a function if the result is successful.
public static Result<TValue> Tap<TValue>(this Result<TValue> result, Action<TValue> onSuccess)
Parameters
Returns
- Result<TValue>
The original result.
Type Parameters
TValueThe type of the value.