On Saturday, December 29, 2018 at 10:59:10 PM UTC-8, 
[email protected] wrote:
>
> While I get that `if !dataset.empty?` vs `unless dataset.any?` is a matter 
> of taste it seems confusing that `.any?` is a valid method but is not 
> equivalent to `!empty?` in terms of query optimisation.
>
> DB[:permissions].any? =>  SELECT * FROM "permissions"
>
> !DB[:permissions].empty? => SELECT 1 AS "one" FROM "permissions" LIMIT 1
>
> I spend my time correcting PRs in my code bases to use !empty? and have 
> had to adjust the default rubocop rules on negated ifs and wondered if 
> there was any reason for the difference and if not whether you would object 
> to such a method being added?
>

Dataset#any? is already defined since Dataset includes Enumerable. any? 
doesn't really mean nonempty? in the general case, and even without the 
block it means is any yielded value not false or nil.  It's possible any? 
without a block could be optimized, though, at least if the dataset doesn't 
have a row_proc associated with it.  However, I'm not sure it makes sense 
to add complexity when you can just use !empty? (and I'm always against 
adding methods just to appease rubocop).

Thanks,
Jeremy

-- 
You received this message because you are subscribed to the Google Groups 
"sequel-talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/sequel-talk.
For more options, visit https://groups.google.com/d/optout.

Reply via email to