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
resultResult<TValue, TErrorIn>The result whose error surface to translate.
mapperFunc<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
Okresult with the original value when the input is a success.
Type Parameters
TValueThe success value type.
TErrorInThe source error type.
TErrorOutThe 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)));