Class ResultTErrorMapErrorExtensions

Namespace
REslava.Result.Extensions
Assembly
REslava.Result.dll

MapError overload for Result<TValue, TError> typed pipelines. Translates the error surface without touching the success value.

public static class ResultTErrorMapErrorExtensions
Inheritance
ResultTErrorMapErrorExtensions
Inherited Members

Methods

MapError<TValue, TErrorIn, TErrorOut>(Result<TValue, TErrorIn>, Func<TErrorIn, TErrorOut>)

Applies mapper to the error when the result is a failure, producing a result with a different error type. The success value is forwarded unchanged. Use this to translate or consolidate error unions at layer boundaries.

public static Result<TValue, TErrorOut> MapError<TValue, TErrorIn, TErrorOut>(this Result<TValue, TErrorIn> result, Func<TErrorIn, TErrorOut> mapper) where TErrorIn : IError where TErrorOut : IError

Parameters

result Result<TValue, TErrorIn>

The result whose error surface to translate.

mapper Func<TErrorIn, TErrorOut>

The function that converts the source error to the target error.

Returns

Result<TValue, TErrorOut>

A result with the mapped error type, or an Ok result with the original value when the input is a success.

Type Parameters

TValue

The success value type.

TErrorIn

The source error type.

TErrorOut

The target error type.

Examples

// Collapse a rich union into a single domain error at a layer boundary
Result<Order, ErrorsOf<ValidationError, InventoryError>> result = ...;

Result<Order, DomainError> translated = result.MapError(e => e.Match(
    v => new DomainError(v.Message),
    i => new DomainError(i.Message)));