Table of Contents

Class RecoverOnFailureExtensions

Namespace
FunctionalDdd
Assembly
FunctionalDdd.RailwayOrientedProgramming.dll

Provides extension methods for recovering from failed results by executing fallback operations.

public static class RecoverOnFailureExtensions
Inheritance
RecoverOnFailureExtensions
Inherited Members

Remarks

This operation runs on the failure track - it only executes when the Result has failed. If the Result is successful, the recovery function is not called.

Recovery allows you to provide alternative paths when a Result fails, similar to try-catch recovery logic but in a functional style. This is useful for implementing fallback strategies, default values, or error recovery.

Methods

RecoverOnFailure<T>(Result<T>, Func<Error, Result<T>>)

Recovers from a failed result by calling the given function with the error.

[RailwayTrack(TrackBehavior.Failure)]
public static Result<T> RecoverOnFailure<T>(this Result<T> result, Func<Error, Result<T>> func)

Parameters

result Result<T>

The result to recover if it's a failure.

func Func<Error, Result<T>>

The function that receives the error and returns a recovery result.

Returns

Result<T>

The original result if success; otherwise the result from the recovery function.

Type Parameters

T

Type of the result value.

RecoverOnFailure<T>(Result<T>, Func<Error, bool>, Func<Error, Result<T>>)

Recovers from a failed result by calling the given function with the error if the predicate returns true.

[RailwayTrack(TrackBehavior.Failure)]
public static Result<T> RecoverOnFailure<T>(this Result<T> result, Func<Error, bool> predicate, Func<Error, Result<T>> func)

Parameters

result Result<T>

The result to recover if it's a failure.

predicate Func<Error, bool>

The predicate to test the error.

func Func<Error, Result<T>>

The function that receives the error and returns a recovery result if the predicate is true.

Returns

Result<T>

The original result if success or predicate is false; otherwise the result from the recovery function.

Type Parameters

T

Type of the result value.

RecoverOnFailure<T>(Result<T>, Func<Error, bool>, Func<Result<T>>)

Recovers from a failed result by calling the given function if the predicate returns true.

[RailwayTrack(TrackBehavior.Failure)]
public static Result<T> RecoverOnFailure<T>(this Result<T> result, Func<Error, bool> predicate, Func<Result<T>> func)

Parameters

result Result<T>

The result to recover if it's a failure.

predicate Func<Error, bool>

The predicate to test the error.

func Func<Result<T>>

The function to call for recovery if the predicate is true.

Returns

Result<T>

The original result if success or predicate is false; otherwise the result from the recovery function.

Type Parameters

T

Type of the result value.

RecoverOnFailure<T>(Result<T>, Func<Result<T>>)

Recovers from a failed result by calling the given function.

[RailwayTrack(TrackBehavior.Failure)]
public static Result<T> RecoverOnFailure<T>(this Result<T> result, Func<Result<T>> func)

Parameters

result Result<T>

The result to recover if it's a failure.

func Func<Result<T>>

The function to call for recovery.

Returns

Result<T>

The original result if success; otherwise the result from the recovery function.

Type Parameters

T

Type of the result value.