Skip to content

Result<TSuccess,TFailure> Class

Represents a result of an operation that can either succeed with a value of type TSuccess or fail with a value of type TFailure.

C#
public abstract record Result<TSuccess,TFailure> : System.IEquatable<Abblix.Utils.Result<TSuccess, TFailure>>

Type parameters

TSuccess

The type of the success result.

TFailure

The type of the failure result.

Inheritance System.Object → Result<TSuccess,TFailure>

Implements System.IEquatable<Abblix.Utils.Result<TSuccess,TFailure>>

Methods

Result<TSuccess,TFailure>.Bind(Action<TSuccess>) Method

Executes the specified action if the result is successful, and returns the original result.

C#
public abstract Abblix.Utils.Result<TSuccess,TFailure> Bind(System.Action<TSuccess> action);

Parameters

action System.Action<TSuccess>

The action to execute if the result is successful.

Returns

Abblix.Utils.Result<TSuccess,TFailure>
The original result after executing the action if successful; otherwise, the failure result.

Result<TSuccess,TFailure>.Bind<TNext>(Func<TSuccess,Result<TNext,TFailure>>) Method

Binds the result to a function that returns a new result, allowing chaining of operations.

C#
public abstract Abblix.Utils.Result<TNext,TFailure> Bind<TNext>(System.Func<TSuccess,Abblix.Utils.Result<TNext,TFailure>> func);

Type parameters

TNext

The type of the success value in the returned result.

Parameters

func System.Func<TSuccess,Abblix.Utils.Result<TNext,TFailure>>

The function to apply to the success value.

Returns

Abblix.Utils.Result<TNext,TFailure>
The result of applying the function if successful; otherwise, the original failure.

Result<TSuccess,TFailure>.BindAsync(Func<TSuccess,Task>) Method

Asynchronously executes the specified action if the result is successful, and returns the original result.

C#
public abstract System.Threading.Tasks.Task<Abblix.Utils.Result<TSuccess,TFailure>> BindAsync(System.Func<TSuccess,System.Threading.Tasks.Task> action);

Parameters

action System.Func<TSuccess,System.Threading.Tasks.Task>

The asynchronous action to execute if the result is successful.

Returns

System.Threading.Tasks.Task<Abblix.Utils.Result<TSuccess,TFailure>>
A task representing the operation, with the original result.

Result<TSuccess,TFailure>.BindAsync<TNext>(Func<TSuccess,Task<Result<TNext,TFailure>>>) Method

Asynchronously binds the result to a function that returns a new result, allowing chaining of operations.

C#
public abstract System.Threading.Tasks.Task<Abblix.Utils.Result<TNext,TFailure>> BindAsync<TNext>(System.Func<TSuccess,System.Threading.Tasks.Task<Abblix.Utils.Result<TNext,TFailure>>> func);

Type parameters

TNext

The type of the success value in the returned result.

Parameters

func System.Func<TSuccess,System.Threading.Tasks.Task<Abblix.Utils.Result<TNext,TFailure>>>

The asynchronous function to apply to the success value.

Returns

System.Threading.Tasks.Task<Abblix.Utils.Result<TNext,TFailure>>
A task representing the result of applying the function if successful; otherwise, the original failure.

Result<TSuccess,TFailure>.Deconstruct(TSuccess, TFailure) Method

Deconstructs the result into separate success and failure values.

C#
public abstract void Deconstruct(out TSuccess? success, out TFailure? failure);

Parameters

success TSuccess

The success value if available; otherwise, null.

failure TFailure

The failure value if available; otherwise, null.

Result<TSuccess,TFailure>.Ensure(Func<TSuccess,bool>, TFailure) Method

Ensures that the success value satisfies the specified predicate; otherwise, returns a failure result.

C#
public abstract Abblix.Utils.Result<TSuccess,TFailure> Ensure(System.Func<TSuccess,bool> predicate, TFailure failure);

Parameters

predicate System.Func<TSuccess,System.Boolean>

The predicate to evaluate the success value.

failure TFailure

The failure value to return if the predicate is not satisfied.

Returns

Abblix.Utils.Result<TSuccess,TFailure>
The original success result if the predicate is satisfied; otherwise, a failure result.

Result<TSuccess,TFailure>.Failure(TFailure) Method

Creates a failed result with the specified value.

C#
public static Abblix.Utils.Result<TSuccess,TFailure> Failure(TFailure value);

Parameters

value TFailure

The failure value.

Returns

Abblix.Utils.Result<TSuccess,TFailure>
A Result<TSuccess,TFailure> representing a failed result.

Result<TSuccess,TFailure>.GetFailure() Method

Gets the failure value.

C#
public abstract TFailure GetFailure();

Returns

TFailure
The failure value.

Exceptions

System.InvalidOperationException
Thrown if the result is a success.

Result<TSuccess,TFailure>.GetSuccess() Method

Gets the success value.

C#
public abstract TSuccess GetSuccess();

Returns

TSuccess
The success value.

Exceptions

System.InvalidOperationException
Thrown if the result is a failure.

Result<TSuccess,TFailure>.Map<TNewSuccess,TNewFailure>(Func<TSuccess,TNewSuccess>, Func<TFailure,TNewFailure>) Method

Maps both success and failure values to new types.

C#
public Abblix.Utils.Result<TNewSuccess,TNewFailure> Map<TNewSuccess,TNewFailure>(System.Func<TSuccess,TNewSuccess> onSuccess, System.Func<TFailure,TNewFailure> onFailure);

Type parameters

TNewSuccess

The type to map the success value to.

TNewFailure

The type to map the failure value to.

Parameters

onSuccess System.Func<TSuccess,TNewSuccess>

The function to apply if the result is successful.

onFailure System.Func<TFailure,TNewFailure>

The function to apply if the result is a failure.

Returns

Abblix.Utils.Result<TNewSuccess,TNewFailure>
A new result with both success and failure values mapped to new types.

Result<TSuccess,TFailure>.MapFailure<T>(Func<TFailure,T>) Method

Synchronously maps a failed result to another type.

C#
public abstract Abblix.Utils.Result<TSuccess,T> MapFailure<T>(System.Func<TFailure,T> onFailure);

Type parameters

T

The type to map the failure value to.

Parameters

onFailure System.Func<TFailure,T>

The mapping function.

Returns

Abblix.Utils.Result<TSuccess,T>
A new result with the mapped failure value or the original success.

Result<TSuccess,TFailure>.MapFailureAsync<T>(Func<TFailure,Task<T>>) Method

Asynchronously maps a failure result to another type.

C#
public abstract System.Threading.Tasks.Task<Abblix.Utils.Result<TSuccess,T>> MapFailureAsync<T>(System.Func<TFailure,System.Threading.Tasks.Task<T>> onFailure);

Type parameters

T

The type to map the failure value to.

Parameters

onFailure System.Func<TFailure,System.Threading.Tasks.Task<T>>

The asynchronous mapping function.

Returns

System.Threading.Tasks.Task<Abblix.Utils.Result<TSuccess,T>>
A new result with the mapped failure value or the original success.

Result<TSuccess,TFailure>.MapSuccess<T>(Func<TSuccess,T>) Method

Synchronously maps a successful result to another type.

C#
public abstract Abblix.Utils.Result<T,TFailure> MapSuccess<T>(System.Func<TSuccess,T> onSuccess);

Type parameters

T

The type to map the success value to.

Parameters

onSuccess System.Func<TSuccess,T>

The mapping function.

Returns

Abblix.Utils.Result<T,TFailure>
A new result with the mapped success value or the original failure.

Result<TSuccess,TFailure>.MapSuccessAsync<T>(Func<TSuccess,Task<T>>) Method

Asynchronously maps a successful result to another type.

C#
public abstract System.Threading.Tasks.Task<Abblix.Utils.Result<T,TFailure>> MapSuccessAsync<T>(System.Func<TSuccess,System.Threading.Tasks.Task<T>> onSuccess);

Type parameters

T

The type to map the success value to.

Parameters

onSuccess System.Func<TSuccess,System.Threading.Tasks.Task<T>>

The asynchronous mapping function.

Returns

System.Threading.Tasks.Task<Abblix.Utils.Result<T,TFailure>>
A new result with the mapped success value or the original failure.

Result<TSuccess,TFailure>.Match<T>(Func<TSuccess,T>, Func<TFailure,T>) Method

Matches the result and invokes the appropriate function depending on whether the result is a success or failure.

C#
public abstract T Match<T>(System.Func<TSuccess,T> onSuccess, System.Func<TFailure,T> onFailure);

Type parameters

T

The return type of the matching functions.

Parameters

onSuccess System.Func<TSuccess,T>

The function to invoke if the result is a success.

onFailure System.Func<TFailure,T>

The function to invoke if the result is a failure.

Returns

T
The result of the matching function.

Result<TSuccess,TFailure>.MatchAsync<T>(Func<TSuccess,Task<T>>, Func<TFailure,Task<T>>) Method

Asynchronously matches the result and invokes the appropriate asynchronous function.

C#
public abstract System.Threading.Tasks.Task<T> MatchAsync<T>(System.Func<TSuccess,System.Threading.Tasks.Task<T>> onSuccess, System.Func<TFailure,System.Threading.Tasks.Task<T>> onFailure);

Type parameters

T

The return type of the matching functions.

Parameters

onSuccess System.Func<TSuccess,System.Threading.Tasks.Task<T>>

The asynchronous function to invoke if the result is a success.

onFailure System.Func<TFailure,System.Threading.Tasks.Task<T>>

The asynchronous function to invoke if the result is a failure.

Returns

System.Threading.Tasks.Task<T>
A task representing the result of the matching function.

Result<TSuccess,TFailure>.MatchAsync<T>(Func<TSuccess,Task<T>>, Func<TFailure,T>) Method

Asynchronously matches the result and invokes the appropriate function.

C#
public abstract System.Threading.Tasks.Task<T> MatchAsync<T>(System.Func<TSuccess,System.Threading.Tasks.Task<T>> onSuccess, System.Func<TFailure,T> onFailure);

Type parameters

T

The return type of the matching functions.

Parameters

onSuccess System.Func<TSuccess,System.Threading.Tasks.Task<T>>

The asynchronous function to invoke if the result is a success.

onFailure System.Func<TFailure,T>

The function to invoke if the result is a failure.

Returns

System.Threading.Tasks.Task<T>
A task representing the result of the matching function.

Result<TSuccess,TFailure>.Success(TSuccess) Method

Creates a successful result with the specified value.

C#
public static Abblix.Utils.Result<TSuccess,TFailure> Success(TSuccess value);

Parameters

value TSuccess

The success value.

Returns

Abblix.Utils.Result<TSuccess,TFailure>
A Result<TSuccess,TFailure> representing a successful result.

Result<TSuccess,TFailure>.TryGetFailure(TFailure) Method

Determines whether the result is a failure.

C#
public abstract bool TryGetFailure(out TFailure value);

Parameters

value TFailure

When this method returns, contains the failure value if the result is a failure; otherwise, the default value.

Returns

System.Boolean
true if the result is a failure; otherwise, false.

Result<TSuccess,TFailure>.TryGetSuccess(TSuccess) Method

Determines whether the result is a success.

C#
public abstract bool TryGetSuccess(out TSuccess value);

Parameters

value TSuccess

When this method returns, contains the success value if the result is successful; otherwise, the default value.

Returns

System.Boolean
true if the result is a success; otherwise, false.

Operators

Result<TSuccess,TFailure>.explicit operator TSuccess(Result<TSuccess,TFailure>) Operator

Converts the result explicitly to the success value.

C#
public static TSuccess explicit operator TSuccess(Abblix.Utils.Result<TSuccess,TFailure> result);

Parameters

result Abblix.Utils.Result<TSuccess,TFailure>

The result instance.

Returns

TSuccess
The success value.

Exceptions

System.InvalidOperationException
Thrown if the result is a failure.

Result<TSuccess,TFailure>.implicit operator Result<TSuccess,TFailure>(TFailure) Operator

Implicitly converts a value of type TFailure to a failed result.

C#
public static Abblix.Utils.Result<TSuccess,TFailure> implicit operator Abblix.Utils.Result<TSuccess,TFailure>(TFailure error);

Parameters

error TFailure

The failure value.

Returns

Abblix.Utils.Result<TSuccess,TFailure>

Result<TSuccess,TFailure>.implicit operator Result<TSuccess,TFailure>(TSuccess) Operator

Implicitly converts a value of type TSuccess to a successful result.

C#
public static Abblix.Utils.Result<TSuccess,TFailure> implicit operator Abblix.Utils.Result<TSuccess,TFailure>(TSuccess value);

Parameters

value TSuccess

The success value.

Returns

Abblix.Utils.Result<TSuccess,TFailure>