[dry-logic] More uniform treatment for the empty? predicate

Hey!

The `empty? 'Predicate checks for some classes and behaves counter intuitively in some common scenarios:

[1] pry(main)> Predicates[:empty?].(Set[])
=> false
[2] pry(main)> Predicates[:empty?].(Set[1])
=> false
[3] pry(main)> Predicates[:included_in?].(Set[1], 1)
=> true
[4] pry(main)> Predicates[:included_in?].(Set[1], 0)
=> false

It may make sense to change this and have this behavior:

[1] pry(main)> Predicates[:empty?].(Set[])
=> true
[2] pry(main)> Predicates[:empty?].(Set[1])
=> false
[3] pry(main)> Predicates[:included_in?].(Set[1], 1)
=> true
[4] pry(main)> Predicates[:included_in?].(Set[1], 0)
=> false

I do not know if it’s a problem to use a respond_to? in this code.

Hey there!

Thanks for bringing this up. I actually thought about the very same thing recently when I was working on improved behavior of filled macro in dry-schema, and it uses filled? which is just !empty?. Anyway, I think you’re right and using respond_to? would be more flexible. Originally I decided to use a hard-coded list of classes because this predicate was supposed to be used for very specific use cases in dry-validation, now it’s a bit different and it seems like a more flexible empty? would be beneficial.

Any thoughts @timriley @flash-gordon? :slight_smile:

Cheers!

I agree. I also hope it won’t backfire :slight_smile: