operator ~ method

  1. @nonVirtual
Spec<T> operator ~()

Returns the logical negation of this spec.

Returns a new spec that is satisfied when this spec is NOT satisfied. Use this to invert rules without creating separate negation specs. Applying negation twice restores the original satisfaction behavior.

Example:

final notAdult = ~IsAdult();
final inactive = ~IsActive();
final notPremium = ~IsPremium();

Implementation

@nonVirtual
Spec<T> operator ~() {
  if (this case _Not<T>(:final spec)) return spec;

  return _Not(this);
}