Skip to content

Create ShortCircuit validator and ShortCircuitable interface#1663

Merged
henriquemoody merged 1 commit into
Respect:mainfrom
henriquemoody:validator/short-circuit
Feb 5, 2026
Merged

Create ShortCircuit validator and ShortCircuitable interface#1663
henriquemoody merged 1 commit into
Respect:mainfrom
henriquemoody:validator/short-circuit

Conversation

@henriquemoody

@henriquemoody henriquemoody commented Feb 1, 2026

Copy link
Copy Markdown
Member

This commit introduces a mechanism for validators to return early once the validation outcome is determined, rather than evaluating all child validators.

The ShortCircuit validator evaluates validators sequentially and stops at the first failure, similar to how PHP's && operator works. This is useful when later validators depend on earlier ones passing, or when you want only the first error message.

The ShortCircuitCapable interface allows composite validators (AllOf, AnyOf, OneOf, NoneOf, Each, All) to implement their own short-circuit logic:

  • AllOf: stops at first failure (like &&)
  • AnyOf: stops at first success (like ||)
  • OneOf: stops when two validators pass (already invalid)
  • NoneOf: stops at first success (already invalid)
  • Each/All: stops at first failing item

Why "ShortCircuit" instead of "FailFast":

The name "FailFast" was initially considered but proved misleading. While AllOf stops on failure (fail fast), AnyOf stops on success (succeed fast), and OneOf stops on the second success. The common behavior is not about failing quickly, but about returning as soon as the outcome is determined—which is exactly what short-circuit evaluation means. This terminology is familiar to developers from boolean operators (&& and ||), making the behavior immediately understandable.


Local benchmark results

Before

Screenshot 2026-02-02 at 00 29 41

After

Screenshot 2026-02-02 at 00 29 09

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants