Class ResultMapErrorExtensions

Namespace
REslava.Result
Assembly
REslava.Result.dll

Extension methods for transforming errors in the failure path of Result types.

public static class ResultMapErrorExtensions
Inheritance
ResultMapErrorExtensions
Inherited Members

Methods

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

Transforms the errors of a failed result using the provided mapper. If the result is successful, it is returned unchanged. The result state (IsSuccess/IsFailure) never changes.

public static Result MapError(this Result result, Func<ImmutableList<IError>, ImmutableList<IError>> mapper)

Parameters

result Result

The result to map errors on.

mapper Func<ImmutableList<IError>, ImmutableList<IError>>

Function that transforms the current error list.

Returns

Result

The original result if successful; otherwise a new failed result with mapped errors.

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

Asynchronously transforms the errors of a failed result using the provided async mapper. If the result is successful, it is returned unchanged.

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

Parameters

result Result

The result to map errors on.

mapper Func<ImmutableList<IError>, Task<ImmutableList<IError>>>

Async function that transforms the current error list.

cancellationToken CancellationToken

Optional cancellation token.

Returns

Task<Result>

The original result if successful; otherwise a new failed result with mapped errors.

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

Asynchronously transforms the errors of a failed result using the provided async mapper. If the result is successful, it is returned unchanged.

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

Parameters

result Result<T>

The result to map errors on.

mapper Func<ImmutableList<IError>, Task<ImmutableList<IError>>>

Async function that transforms the current error list.

cancellationToken CancellationToken

Optional cancellation token.

Returns

Task<Result<T>>

The original result if successful; otherwise a new failed result with mapped errors.

Type Parameters

T

The value type.

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

Transforms the errors of a failed result using the provided mapper. If the result is successful, it is returned unchanged. The result state (IsSuccess/IsFailure) never changes.

public static Result<T> MapError<T>(this Result<T> result, Func<ImmutableList<IError>, ImmutableList<IError>> mapper)

Parameters

result Result<T>

The result to map errors on.

mapper Func<ImmutableList<IError>, ImmutableList<IError>>

Function that transforms the current error list.

Returns

Result<T>

The original result if successful; otherwise a new failed result with mapped errors.

Type Parameters

T

The value type.