Class CheckExtensions
- Namespace
- Trellis
- Assembly
- Trellis.Results.dll
Provides extension methods for running validation functions on Result values while preserving the original value on success. If the check fails, its failure is returned.
public static class CheckExtensions
- Inheritance
-
CheckExtensions
- Inherited Members
Remarks
Check is semantically equivalent to result.Bind(v => func(v).Map(_ => v)) but is
implemented directly for efficiency. This is useful when you want to validate a value using
a function that returns a Result, but you want to keep the original value flowing through
the pipeline rather than the check function's return value.
Methods
Check<T>(Result<T>, Func<T, Result<Unit>>)
Runs a validation function that returns Result<TValue> on the success value, preserving the original value on success. Common for void validations.
public static Result<T> Check<T>(this Result<T> result, Func<T, Result<Unit>> func)
Parameters
resultResult<T>The result to check.
funcFunc<T, Result<Unit>>The validation function that returns a Result of Unit.
Returns
- Result<T>
The original result if the check passes; otherwise the check's failure.
Type Parameters
TType of the original result value.
Check<T, TK>(Result<T>, Func<T, Result<TK>>)
Runs a validation function on the success value, discarding the check result's value on success and preserving the original value. If the check fails, its failure is returned.
public static Result<T> Check<T, TK>(this Result<T> result, Func<T, Result<TK>> func)
Parameters
resultResult<T>The result to check.
funcFunc<T, Result<TK>>The validation function that returns a Result.
Returns
- Result<T>
The original result if the check passes; otherwise the check's failure.
Type Parameters
TType of the original result value.
TKType of the check function's result value (discarded on success).