You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Non-generic to generic Result MapFailure method #18
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")
Activity