Table of Contents

Class EnsureAllExtensions

Namespace
Trellis
Assembly
Trellis.Core.dll

Provides extension methods for ensuring multiple conditions on Result values simultaneously. Unlike Ensure<TValue>(Result<TValue>, Func<TValue, bool>, Error) which short-circuits on the first failure, EnsureAll runs ALL checks and accumulates errors into a single combined error.

public static class EnsureAllExtensions
Inheritance
EnsureAllExtensions
Inherited Members

Remarks

This is the "applicative" validation style — validate everything, merge errors. Useful for form validation where users need to see all errors at once.

Methods

EnsureAll<TValue>(Result<TValue>, params (Func<TValue, bool> predicate, Func<TValue, Error> errorFactory)[])

Runs every predicate and accumulates errors created lazily for failed checks. An upstream failure is returned unchanged without invoking predicates or factories.

public static Result<TValue> EnsureAll<TValue>(this Result<TValue> result, params (Func<TValue, bool> predicate, Func<TValue, Error> errorFactory)[] checks)

Parameters

result Result<TValue>

The result to validate.

checks (Func<TValue, bool> predicate, Func<TValue, Error> errorFactory)[]

Predicates and factories that receive the successful value. A factory is invoked exactly once when its predicate fails.

Returns

Result<TValue>

The original result if all checks pass; otherwise all accumulated errors.

Type Parameters

TValue

Type of the result value.

Remarks

The constant-error overload has higher overload-resolution priority so existing empty-check and null-literal calls retain their original meaning.

Exceptions

ArgumentNullException

The checks array or a checked delegate is null.

InvalidOperationException

An invoked factory returns null.

EnsureAll<TValue>(Result<TValue>, params (Func<TValue, bool> predicate, Error error)[])

Runs all validation checks on the result value and accumulates any failures into a single error. If the result is already a failure, it is returned unchanged.

public static Result<TValue> EnsureAll<TValue>(this Result<TValue> result, params (Func<TValue, bool> predicate, Error error)[] checks)

Parameters

result Result<TValue>

The result to validate.

checks (Func<TValue, bool> predicate, Error error)[]

The validation checks to run, each consisting of a predicate and an error to use if the predicate fails.

Returns

Result<TValue>

The original result if all checks pass; otherwise a failure with all accumulated errors.

Type Parameters

TValue

Type of the result value.