Class ResultTErrorTapExtensions

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

Tap and TapOnFailure overloads for Result<TValue, TError> typed pipelines. Execute side effects without altering the result — the original result is always returned.

public static class ResultTErrorTapExtensions
Inheritance
ResultTErrorTapExtensions
Inherited Members

Methods

TapOnFailure<TValue, TError>(Result<TValue, TError>, Action<TError>)

Executes a side effect on the error value and returns the original result unchanged. The action is not called if the result is a success.

public static Result<TValue, TError> TapOnFailure<TValue, TError>(this Result<TValue, TError> result, Action<TError> action) where TError : IError

Parameters

result Result<TValue, TError>

The result to tap into.

action Action<TError>

The side effect to run on failure.

Returns

Result<TValue, TError>

The original result, unchanged.

Type Parameters

TValue

The value type.

TError

The error type. Must implement IError.

Examples

Validate(req)
    .TapOnFailure(err => logger.LogWarning("Validation failed: {Msg}", err.Message))
    .Bind(ReserveInventory);

Tap<TValue, TError>(Result<TValue, TError>, Action<TValue>)

Executes a side effect on the success value and returns the original result unchanged. The action is not called if the result is a failure.

public static Result<TValue, TError> Tap<TValue, TError>(this Result<TValue, TError> result, Action<TValue> action) where TError : IError

Parameters

result Result<TValue, TError>

The result to tap into.

action Action<TValue>

The side effect to run on success.

Returns

Result<TValue, TError>

The original result, unchanged.

Type Parameters

TValue

The value type.

TError

The error type. Must implement IError.

Examples

Validate(req)
    .Tap(order => logger.LogInformation("Order {Id} validated", order.Id))
    .Bind(ReserveInventory);