From: masafumi.o1988@... Date: 2020-12-09T13:56:42+00:00 Subject: [ruby-core:101341] [Ruby master Feature#17333] Enumerable#many? Issue #17333 has been updated by okuramasafumi (Masafumi OKURA). Here are a usecase where we could use `many?` over `count` for better performance. https://github.com/Homebrew/brew/blob/master/Library/Homebrew/cask/audit.rb#L188 This code, `cask.artifacts.count { |k| k.is_a?(Artifact::Uninstall) } > 1` calls block as many times as the size of `cask.artifact`. In contrast, `cask.artifacts.many? { |k| k.is_a?(Artifact::Uninstall) }` calls blocks only before finding second matching artifact, which could improve performance. Like this case where we cannot expect the size of collection, using `count` could cost a lot and introducing `many?` could help. ---------------------------------------- Feature #17333: Enumerable#many? https://bugs.ruby-lang.org/issues/17333#change-89042 * 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: