๐ ResultSideEffectExtensions
API Reference
namespace Zentient . Results
Provides fluent, expressive side-effect extension methods for IResult
and IResult<T>
. These enable conditional execution of actionsโsuch as logging, metrics, or notificationsโwithout mutating the result or disrupting the functional chain.
Property
Value
๐ฆ Assembly
Zentient.Results.dll
๐ Visibility
public static class
๐งฑ Category
Result Extensions
๐ฏ Purpose
Tap-style side-effect hooks
var result = DoSomething ( )
. OnSuccess ( ( ) => Log . Information ( "Success!" ) )
. OnFailure ( errors => Log . Error ( "Failure: {Errors}" , errors ) ) ;
var result = GetUser ( )
. OnSuccess ( user => Audit ( user ) )
. OnFailure ( errs => AlertAdmin ( errs ) ) ;
๐น OnSuccess(this IResult result, Action onSuccess)
Executes onSuccess
only if the non-generic IResult
is successful.
Parameter
Type
Description
result
IResult
The result to inspect.
onSuccess
Action
Action to execute on success.
Returns
IResult
The original result (unmodified).
๐ Throws ArgumentNullException
if result
or onSuccess
is null
.
๐น OnSuccess<TValue>(this IResult<TValue> result, Action<TValue> onSuccess)
Executes onSuccess
only if the generic result is successful, passing the success value.
Parameter
Type
Description
result
IResult<TValue>
The result to inspect.
onSuccess
Action<TValue>
Action to execute with the value.
Returns
IResult<TValue>
The original result (unmodified).
๐ Throws ArgumentNullException
if any argument is null
.
๐น OnFailure(this IResult result, Action<IReadOnlyList<ErrorInfo>> onFailure)
Executes onFailure
only if the result indicates failure, passing the full error list.
Parameter
Type
Description
result
IResult
The result to inspect.
onFailure
Action<IReadOnlyList<ErrorInfo>>
Action to execute on failure.
Returns
IResult
The original result (unmodified).
๐ Throws ArgumentNullException
if any argument is null
.
๐น OnFailure<TValue>(this IResult<TValue> result, Action<IReadOnlyList<ErrorInfo>> onFailure)
Executes onFailure
only if the generic result is failure, passing the error list.
Parameter
Type
Description
result
IResult<TValue>
The result to inspect.
onFailure
Action<IReadOnlyList<ErrorInfo>>
Action to execute on failure.
Returns
IResult<TValue>
The original result (unmodified).
๐ Throws ArgumentNullException
if any argument is null
.
Scenario
Recommendation
Logging result outcomes
Use OnSuccess
/ OnFailure
for non-intrusive logging
Adding metrics or telemetry
Inject counters or traces inside tap callbacks
Maintaining functional purity
Avoid mutating shared state inside side-effect actions
Fluent method chaining
All methods return the original result for chaining
return SomeOperation ( )
. OnSuccess ( ( ) => logger . Log ( "All good" ) )
. OnFailure ( errors => logger . Warn ( "Failed: {0}" , string . Join ( ", " , errors ) ) ) ;