check<CheckedValue> method

Result<CheckedValue> check<CheckedValue>(
  1. Object? outcomes,
  2. CheckedValue data,
  3. bool condition()
)

Validates a condition inline, carrying data on both paths.

condition is the success predicate — return true when valid. On success, data is the value. On failure, data becomes the context, so the caller always has the validated object available either way:

Result<String> _requireEmail() =>
    check('emailInvalid', email, () => email.contains('@'));
// Success('emailInvalid', 'alice@test.com')  — when valid
// Failure('emailInvalid', 'notanemail')       — when invalid

Because check returns Result<CheckedValue> rather than Result<Value>, chain it via andThen((_) => nextStep()) to discard the intermediate value and continue the pipeline.

Implementation

Result<CheckedValue> check<CheckedValue>(Object? outcomes, CheckedValue data, bool Function() condition) =>
    condition() ? Success(outcomes, data) : Failure(outcomes, data);