Class ResultOrExtensions

Namespace
REslava.Result
Assembly
REslava.Result.dll

Extension methods for providing fallback results on failure.

public static class ResultOrExtensions
Inheritance
ResultOrExtensions
Inherited Members

Methods

Or(Result, Result)

Returns the result if successful; otherwise returns the provided fallback.

public static Result Or(this Result result, Result fallback)

Parameters

result Result

The result to check.

fallback Result

The fallback result to use on failure.

Returns

Result

The original result if successful; otherwise fallback.

OrElse(Result, Func<ImmutableList<IError>, Result>)

Returns the result if successful; otherwise invokes the fallback factory with the current errors.

public static Result OrElse(this Result result, Func<ImmutableList<IError>, Result> fallbackFactory)

Parameters

result Result

The result to check.

fallbackFactory Func<ImmutableList<IError>, Result>

Function that receives the current errors and produces a fallback result.

Returns

Result

The original result if successful; otherwise the result of fallbackFactory.

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

Returns the result if successful; otherwise asynchronously invokes the fallback factory with the current errors.

public static Task<Result> OrElseAsync(this Result result, Func<ImmutableList<IError>, Task<Result>> fallbackFactory, CancellationToken cancellationToken = default)

Parameters

result Result

The result to check.

fallbackFactory Func<ImmutableList<IError>, Task<Result>>

Async function that receives the current errors and produces a fallback result.

cancellationToken CancellationToken

Optional cancellation token.

Returns

Task<Result>

The original result if successful; otherwise the result of fallbackFactory.

OrElseAsync<T>(Result<T>, Func<ImmutableList<IError>, Task<Result<T>>>, CancellationToken)

Returns the result if successful; otherwise asynchronously invokes the fallback factory with the current errors.

public static Task<Result<T>> OrElseAsync<T>(this Result<T> result, Func<ImmutableList<IError>, Task<Result<T>>> fallbackFactory, CancellationToken cancellationToken = default)

Parameters

result Result<T>

The result to check.

fallbackFactory Func<ImmutableList<IError>, Task<Result<T>>>

Async function that receives the current errors and produces a fallback result.

cancellationToken CancellationToken

Optional cancellation token.

Returns

Task<Result<T>>

The original result if successful; otherwise the result of fallbackFactory.

Type Parameters

T

The value type.

OrElse<T>(Result<T>, Func<ImmutableList<IError>, Result<T>>)

Returns the result if successful; otherwise invokes the fallback factory with the current errors.

public static Result<T> OrElse<T>(this Result<T> result, Func<ImmutableList<IError>, Result<T>> fallbackFactory)

Parameters

result Result<T>

The result to check.

fallbackFactory Func<ImmutableList<IError>, Result<T>>

Function that receives the current errors and produces a fallback result.

Returns

Result<T>

The original result if successful; otherwise the result of fallbackFactory.

Type Parameters

T

The value type.

Or<T>(Result<T>, Result<T>)

Returns the result if successful; otherwise returns the provided fallback.

public static Result<T> Or<T>(this Result<T> result, Result<T> fallback)

Parameters

result Result<T>

The result to check.

fallback Result<T>

The fallback result to use on failure.

Returns

Result<T>

The original result if successful; otherwise fallback.

Type Parameters

T

The value type.