There is a MapFailure method on Result<T>, but not on Result. I just encountered a situation where it makes sense to do so.
This method should be added to the non-generic Result class (note the lack of <T> compared to the generic Result<T> version):
/// <summary>/// Maps the failure result to another type./// </summary>/// <typeparam name="TOther">The type to map to.</typeparam>/// <returns>A <see cref="Result{TOther}"/>.</returns>/// <exception cref="InvalidOperationException">Thrown if the result type is not known.</exception>publicResult<TOther>MapFailure<TOther>()=>thisswitch{SuccessResult=>thrownewInvalidOperationException("Cannot map failure on success result"),ValidationFailedResultvalidationFailed=>Result<TOther>.ValidationFailed(validationFailed.Errors),UnauthorizedResultunauthorized=>Result<TOther>.Unauthorized(unauthorized.Message),PreconditionFailedResultpreconditionFailed=>Result<TOther>.PreconditionFailed(preconditionFailed.Reason,preconditionFailed.Message),
_ =>thrownewInvalidOperationException("Unknown result type")
There is a MapFailure method on
Result<T>, but not onResult. I just encountered a situation where it makes sense to do so.This method should be added to the non-generic Result class (note the lack of
<T>compared to the genericResult<T>version):