Class TapExtensions
- Namespace
- FunctionalDdd
- Assembly
- FunctionalDdd.RailwayOrientedProgramming.dll
Provides extension methods for executing side effects on successful Results without changing the Result.
public static class TapExtensions
- Inheritance
-
TapExtensions
- Inherited Members
Examples
var result = GetUser(id)
.Tap(user => _logger.LogInformation("Found user: {Name}", user.Name))
.Bind(user => ValidateUser(user))
.Tap(() => _metrics.IncrementCounter("user.validated"));
Remarks
Tap is useful for performing side effects (like logging, auditing, or debugging) in a functional pipeline without breaking the chain. The action is only executed if the Result is successful, and the original Result is always returned unchanged. This allows you to "peek" at values flowing through the pipeline.
Methods
Tap<TValue>(Result<TValue>, Action)
Executes the given action if the result is a success. Returns the original result unchanged.
public static Result<TValue> Tap<TValue>(this Result<TValue> result, Action action)
Parameters
resultResult<TValue>The result to tap.
actionActionThe action to execute if the result is successful.
Returns
- Result<TValue>
The original result unchanged.
Type Parameters
TValueType of the result value.
Tap<TValue>(Result<TValue>, Action<TValue>)
Executes the given action with the value if the result is a success. Returns the original result unchanged.
public static Result<TValue> Tap<TValue>(this Result<TValue> result, Action<TValue> action)
Parameters
resultResult<TValue>The result to tap.
actionAction<TValue>The action to execute with the value if the result is successful.
Returns
- Result<TValue>
The original result unchanged.
Type Parameters
TValueType of the result value.