ResultExtensions Class
Provides extension methods for working with Result<TSuccess,TFailure> types.
public static class ResultExtensionsInheritance System.Object → ResultExtensions
Methods
ResultExtensions.Bind<TSuccess,TFailure,TNext>(this Task<Result<TSuccess,TFailure>>, Func<TSuccess,Result<TNext,TFailure>>) Method
Binds a synchronous result-producing function to the result of a task, if the result is successful.
public static System.Threading.Tasks.Task<Abblix.Utils.Result<TNext,TFailure>> Bind<TSuccess,TFailure,TNext>(this System.Threading.Tasks.Task<Abblix.Utils.Result<TSuccess,TFailure>> resultTask, System.Func<TSuccess,Abblix.Utils.Result<TNext,TFailure>> func);Type parameters
TSuccess
The type of the original success value.
TFailure
The type of the failure.
TNext
The type of the next success value.
Parameters
resultTask System.Threading.Tasks.Task<Abblix.Utils.Result<TSuccess,TFailure>>
The asynchronous task producing a result.
func System.Func<TSuccess,Abblix.Utils.Result<TNext,TFailure>>
The synchronous function to bind if the result is successful.
Returns
System.Threading.Tasks.Task<Abblix.Utils.Result<TNext,TFailure>>
A task representing the new result after binding.
ResultExtensions.BindAsync<TSuccess,TFailure,TNext>(this Task<Result<TSuccess,TFailure>>, Func<TSuccess,Task<Result<TNext,TFailure>>>) Method
Asynchronously binds a result-producing function to the result of a task, if the result is successful.
public static System.Threading.Tasks.Task<Abblix.Utils.Result<TNext,TFailure>> BindAsync<TSuccess,TFailure,TNext>(this System.Threading.Tasks.Task<Abblix.Utils.Result<TSuccess,TFailure>> resultTask, System.Func<TSuccess,System.Threading.Tasks.Task<Abblix.Utils.Result<TNext,TFailure>>> func);Type parameters
TSuccess
The type of the original success value.
TFailure
The type of the failure.
TNext
The type of the next success value.
Parameters
resultTask System.Threading.Tasks.Task<Abblix.Utils.Result<TSuccess,TFailure>>
The asynchronous task producing a result.
func System.Func<TSuccess,System.Threading.Tasks.Task<Abblix.Utils.Result<TNext,TFailure>>>
The function to bind if the result is successful.
Returns
System.Threading.Tasks.Task<Abblix.Utils.Result<TNext,TFailure>>
A task representing the new result after binding.
ResultExtensions.Ensure<TSuccess,TFailure>(this TSuccess, Func<TSuccess,bool>, TFailure) Method
Ensures that a value satisfies a specified predicate; otherwise, returns a failure.
public static Abblix.Utils.Result<TSuccess,TFailure> Ensure<TSuccess,TFailure>(this TSuccess value, System.Func<TSuccess,bool> predicate, TFailure failure);Type parameters
TSuccess
The type of the value.
TFailure
The type of the failure.
Parameters
value TSuccess
The value to validate.
predicate System.Func<TSuccess,System.Boolean>
The predicate to evaluate.
failure TFailure
The failure to return if the predicate is not satisfied.
Returns
Abblix.Utils.Result<TSuccess,TFailure>
A successful result if the predicate is satisfied; otherwise, a failed result.
ResultExtensions.EnsureAsync<TSuccess,TFailure>(this Task<TSuccess>, Func<TSuccess,bool>, TFailure) Method
Asynchronously ensures that a value satisfies a specified predicate; otherwise, returns a failure.
public static System.Threading.Tasks.Task<Abblix.Utils.Result<TSuccess,TFailure>> EnsureAsync<TSuccess,TFailure>(this System.Threading.Tasks.Task<TSuccess> valueTask, System.Func<TSuccess,bool> predicate, TFailure failure);Type parameters
TSuccess
The type of the value.
TFailure
The type of the failure.
Parameters
valueTask System.Threading.Tasks.Task<TSuccess>
The asynchronous task producing the value.
predicate System.Func<TSuccess,System.Boolean>
The predicate to evaluate.
failure TFailure
The failure to return if the predicate is not satisfied.
Returns
System.Threading.Tasks.Task<Abblix.Utils.Result<TSuccess,TFailure>>
A task representing the successful or failed result.
ResultExtensions.FailIfNull<TSuccess,TFailure>(this TSuccess, Func<TFailure>) Method
Converts a nullable value into a successful result if not null; otherwise, returns a failure.
public static Abblix.Utils.Result<TSuccess,TFailure> FailIfNull<TSuccess,TFailure>(this TSuccess? value, System.Func<TFailure> failure);Type parameters
TSuccess
The type of the value.
TFailure
The type of the failure.
Parameters
value TSuccess
The nullable value to check.
failure System.Func<TFailure>
The failure to return if the value is null.
Returns
Abblix.Utils.Result<TSuccess,TFailure>
A successful result if the value is not null; otherwise, a failed result.
ResultExtensions.FailIfNull<TSuccess,TFailure>(this TSuccess, TFailure) Method
Converts a nullable value into a successful result if not null; otherwise, returns a failure.
public static Abblix.Utils.Result<TSuccess,TFailure> FailIfNull<TSuccess,TFailure>(this TSuccess? value, TFailure failure);Type parameters
TSuccess
The type of the value.
TFailure
The type of the failure.
Parameters
value TSuccess
The nullable value to check.
failure TFailure
The failure to return if the value is null.
Returns
Abblix.Utils.Result<TSuccess,TFailure>
A successful result if the value is not null; otherwise, a failed result.
ResultExtensions.FailIfNullAsync<TSuccess,TFailure>(this Task<TSuccess>, Func<TFailure>) Method
Asynchronously converts a nullable value into a successful result if not null; otherwise, returns a failure.
public static System.Threading.Tasks.Task<Abblix.Utils.Result<TSuccess,TFailure>> FailIfNullAsync<TSuccess,TFailure>(this System.Threading.Tasks.Task<TSuccess?> valueTask, System.Func<TFailure> failure);Type parameters
TSuccess
The type of the value.
TFailure
The type of the failure.
Parameters
valueTask System.Threading.Tasks.Task<TSuccess>
The asynchronous task producing the nullable value.
failure System.Func<TFailure>
The failure to return if the value is null.
Returns
System.Threading.Tasks.Task<Abblix.Utils.Result<TSuccess,TFailure>>
A task representing the successful or failed result.
ResultExtensions.FailIfNullAsync<TSuccess,TFailure>(this Task<TSuccess>, TFailure) Method
Asynchronously converts a nullable value into a successful result if not null; otherwise, returns a failure.
public static System.Threading.Tasks.Task<Abblix.Utils.Result<TSuccess,TFailure>> FailIfNullAsync<TSuccess,TFailure>(this System.Threading.Tasks.Task<TSuccess?> valueTask, TFailure failure);Type parameters
TSuccess
The type of the value.
TFailure
The type of the failure.
Parameters
valueTask System.Threading.Tasks.Task<TSuccess>
The asynchronous task producing the nullable value.
failure TFailure
The failure to return if the value is null.
Returns
System.Threading.Tasks.Task<Abblix.Utils.Result<TSuccess,TFailure>>
A task representing the successful or failed result.
ResultExtensions.MapSuccessAsync<TSuccess,TFailure,TNext>(this Task<Result<TSuccess,TFailure>>, Func<TSuccess,Task<TNext>>) Method
Asynchronously maps a successful result to another type.
public static System.Threading.Tasks.Task<Abblix.Utils.Result<TNext,TFailure>> MapSuccessAsync<TSuccess,TFailure,TNext>(this System.Threading.Tasks.Task<Abblix.Utils.Result<TSuccess,TFailure>> resultTask, System.Func<TSuccess,System.Threading.Tasks.Task<TNext>> onSuccess);Type parameters
TSuccess
The type of the original success value.
TFailure
The type of the failure.
TNext
The type to map the success value to.
Parameters
resultTask System.Threading.Tasks.Task<Abblix.Utils.Result<TSuccess,TFailure>>
The asynchronous task producing a result.
onSuccess System.Func<TSuccess,System.Threading.Tasks.Task<TNext>>
The asynchronous mapping function.
Returns
System.Threading.Tasks.Task<Abblix.Utils.Result<TNext,TFailure>>
A task representing the new result with the mapped success value.