Conditional validations and using macros/predicates in rules

schema = Dry::Validation.Form do
  required(:single).filled(:bool?)
  optional(:participant2).maybe(:str?)

  rule(second_participant: [:single, :participant2]) do |single, participant2|
    single.false?.then(participant2.filled?)
  end
end

how to achieve this behavior today, in version 1.6 ?

  1. How to write conditional validations like ActiveModel if:, dependent on another key in schema
  2. using macros/predicates like filled in rules. (participant2.filled?)

I read all docs,

   schema = Dry::Validation.Form do
      required(:single).filled(:bool?)
      optional(:participant2).maybe(:str?)

      rule(:participant2, :single) do
         key.failure(:must_be_filled) if !values[:single] && values[:participant2].blank?
         #  How to remove code duplication (replace key.failure(:must_be_filled) to participant2.filled?)
         # this is possible?
      end
    end

(replace key.failure(:must_be_filled) to participant2.filled?)

This is not possible because rule API doesn’t use predicates anymore. You can reduce complexity in various cases via macros though. So maybe that’s what you’re looking for: dry-rb - dry-validation v1.6 - Macros