Table of Contents

Class CheckIfExtensions

Namespace
Trellis
Assembly
Trellis.Results.dll

Provides conditional check extension methods for Result values. The check function is only invoked when the condition or predicate is true; otherwise the original result passes through unchanged.

public static class CheckIfExtensions
Inheritance
CheckIfExtensions
Inherited Members

Remarks

CheckIf combines the conditional behavior of MapIfExtensions with the validation semantics of CheckExtensions. Use it when a validation step should only run under certain circumstances.

Methods

CheckIf<T>(Result<T>, bool, Func<T, Result<Unit>>)

Conditionally runs a validation function when the boolean condition is true. Convenience overload for check functions returning Result<TValue>.

public static Result<T> CheckIf<T>(this Result<T> result, bool condition, Func<T, Result<Unit>> func)

Parameters

result Result<T>

The result to check.

condition bool

The condition that must be true for the check to run.

func Func<T, Result<Unit>>

The validation function that returns a Result of Unit.

Returns

Result<T>

The original result if the condition is false or the check passes; otherwise the check's failure.

Type Parameters

T

Type of the original result value.

CheckIf<T>(Result<T>, Func<T, bool>, Func<T, Result<Unit>>)

Conditionally runs a validation function when the predicate returns true for the success value. Convenience overload for check functions returning Result<TValue>.

public static Result<T> CheckIf<T>(this Result<T> result, Func<T, bool> predicate, Func<T, Result<Unit>> func)

Parameters

result Result<T>

The result to check.

predicate Func<T, bool>

The predicate to evaluate against the success value.

func Func<T, Result<Unit>>

The validation function that returns a Result of Unit.

Returns

Result<T>

The original result if the predicate is false or the check passes; otherwise the check's failure.

Type Parameters

T

Type of the original result value.

CheckIf<T, TK>(Result<T>, bool, Func<T, Result<TK>>)

Conditionally runs a validation function when the boolean condition is true. If the result is a failure, or the condition is false, returns the original result unchanged.

public static Result<T> CheckIf<T, TK>(this Result<T> result, bool condition, Func<T, Result<TK>> func)

Parameters

result Result<T>

The result to check.

condition bool

The condition that must be true for the check to run.

func Func<T, Result<TK>>

The validation function that returns a Result.

Returns

Result<T>

The original result if the condition is false or the check passes; otherwise the check's failure.

Type Parameters

T

Type of the original result value.

TK

Type of the check function's result value (discarded on success).

CheckIf<T, TK>(Result<T>, Func<T, bool>, Func<T, Result<TK>>)

Conditionally runs a validation function when the predicate returns true for the success value. If the result is a failure, or the predicate returns false, returns the original result unchanged.

public static Result<T> CheckIf<T, TK>(this Result<T> result, Func<T, bool> predicate, Func<T, Result<TK>> func)

Parameters

result Result<T>

The result to check.

predicate Func<T, bool>

The predicate to evaluate against the success value.

func Func<T, Result<TK>>

The validation function that returns a Result.

Returns

Result<T>

The original result if the predicate is false or the check passes; otherwise the check's failure.

Type Parameters

T

Type of the original result value.

TK

Type of the check function's result value (discarded on success).