From: daniel@...42.com Date: 2020-12-10T04:13:48+00:00 Subject: [ruby-core:101352] [Ruby master Feature#17333] Enumerable#many? Issue #17333 has been updated by Dan0042 (Daniel DeLorme). That `artifacts.count` code was a bad example; since this is error checking, in the normal case you will check all elements and pass. Only in the failure case would you avoid checking all elements, and at that point this kind of performance optimization is of no concern. Like sawa I feel that `many?` in itself is too specific, not useful enough to be worth adding in core. I could sort-of imagine making this a special case of `one?`, where 0 items is nil and > 1 is false (so `many?` is `one? == false`). Or if we could pass a block to `first` then we could have `first(2){ condition }.size > 1` in order to be efficient. Or by adding a `max` keyword parameter to enumerable operations such as select/reject/count, we could do `count(max: 2){ condition } > 1`. Imho these are all more generic and better solutions than this overly specific `many?` ---------------------------------------- Feature #17333: Enumerable#many? https://bugs.ruby-lang.org/issues/17333#change-89058 * Author: okuramasafumi (Masafumi OKURA) * Status: Open * Priority: Normal ---------------------------------------- `Enumerable#many?` method is implemented in ActiveSupport. https://api.rubyonrails.org/classes/Enumerable.html#method-i-many-3F However, it's slightly different from Ruby's core methods such as `one?` or `all?`, where they take pattern argument. I believe these methods should behave the same so that it's easier to guess and learn. We already have `none?`, `one?`, `any?` and `all?`, which translate into `== 0`, `== 1`, `> 0` and `== self.size`. `many?` method translates into `> 1`, which is reasonable to exist. Currently we need to write something this: ```ruby [1, 2, 3].count(&:odd?) > 1 ``` With `many?`, we can make it simpler: ```ruby [1, 2, 3].many?(&:odd?) ``` Pull Request on GitHub is available at https://github.com/ruby/ruby/pull/3785 -- https://bugs.ruby-lang.org/ Unsubscribe: