[ruby-core:123754] [Ruby Feature#21678] Enumerable#rfind
Issue #21678 has been reported by kddnewton (Kevin Newton). ---------------------------------------- Feature #21678: Enumerable#rfind https://bugs.ruby-lang.org/issues/21678 * Author: kddnewton (Kevin Newton) * Status: Open ---------------------------------------- I'd like to introduce `rfind` to enumerable, which would effectively be the same as `reverse_each.find`. I've found myself using this a surprising number of times, and have been surprised at its omission. That means either falling back to `reverse_each` or `rindex`. For context, here are a couple of examples of this in the wild: * [pry](https://github.com/pry/pry/blob/80816f596774d00afdc81a555724b0819bf26782/lib...) * [bundler](https://github.com/ruby/rubygems/blob/e4fd4ee3fad005fce1dbcbeffd47e7199243bc...) * [textbringer](https://github.com/shugo/textbringer/blob/738d318558045efc9d978e6b5616d2641a...) -- https://bugs.ruby-lang.org/
Issue #21678 has been updated by nobu (Nobuyoshi Nakada). https://github.com/nobu/ruby/tree/refs/heads/enum-rfind ---------------------------------------- Feature #21678: Enumerable#rfind https://bugs.ruby-lang.org/issues/21678#change-115160 * Author: kddnewton (Kevin Newton) * Status: Open ---------------------------------------- I'd like to introduce `rfind` to enumerable, which would effectively be the same as `reverse_each.find`. I've found myself using this a surprising number of times, and have been surprised at its omission. That means either falling back to `reverse_each` or `rindex`. For context, here are a couple of examples of this in the wild: * [pry](https://github.com/pry/pry/blob/80816f596774d00afdc81a555724b0819bf26782/lib...) * [bundler](https://github.com/ruby/rubygems/blob/e4fd4ee3fad005fce1dbcbeffd47e7199243bc...) * [textbringer](https://github.com/shugo/textbringer/blob/738d318558045efc9d978e6b5616d2641a...) -- https://bugs.ruby-lang.org/
Issue #21678 has been updated by matz (Yukihiro Matsumoto). The `Enumerable` module basically relies on the `#each` method which only works in the forward direction, and the only way to scan backwards is to convert it to an array once. I agree with `Array#rfind` (which can be implemented efficiently), but is it necessary for the `Enumerable` module as well? Matz. ---------------------------------------- Feature #21678: Enumerable#rfind https://bugs.ruby-lang.org/issues/21678#change-115173 * Author: kddnewton (Kevin Newton) * Status: Open ---------------------------------------- I'd like to introduce `rfind` to enumerable, which would effectively be the same as `reverse_each.find`. I've found myself using this a surprising number of times, and have been surprised at its omission. That means either falling back to `reverse_each` or `rindex`. For context, here are a couple of examples of this in the wild: * [pry](https://github.com/pry/pry/blob/80816f596774d00afdc81a555724b0819bf26782/lib...) * [bundler](https://github.com/ruby/rubygems/blob/e4fd4ee3fad005fce1dbcbeffd47e7199243bc...) * [textbringer](https://github.com/shugo/textbringer/blob/738d318558045efc9d978e6b5616d2641a...) -- https://bugs.ruby-lang.org/
Issue #21678 has been updated by kddnewton (Kevin Newton). That makes sense! I'm totally fine with it just being on Array. ---------------------------------------- Feature #21678: Enumerable#rfind https://bugs.ruby-lang.org/issues/21678#change-115190 * Author: kddnewton (Kevin Newton) * Status: Open ---------------------------------------- I'd like to introduce `rfind` to enumerable, which would effectively be the same as `reverse_each.find`. I've found myself using this a surprising number of times, and have been surprised at its omission. That means either falling back to `reverse_each` or `rindex`. For context, here are a couple of examples of this in the wild: * [pry](https://github.com/pry/pry/blob/80816f596774d00afdc81a555724b0819bf26782/lib...) * [bundler](https://github.com/ruby/rubygems/blob/e4fd4ee3fad005fce1dbcbeffd47e7199243bc...) * [textbringer](https://github.com/shugo/textbringer/blob/738d318558045efc9d978e6b5616d2641a...) -- https://bugs.ruby-lang.org/
Issue #21678 has been updated by kddnewton (Kevin Newton). https://github.com/ruby/ruby/pull/15189 ---------------------------------------- Feature #21678: Enumerable#rfind https://bugs.ruby-lang.org/issues/21678#change-115202 * Author: kddnewton (Kevin Newton) * Status: Open ---------------------------------------- I'd like to introduce `rfind` to enumerable, which would effectively be the same as `reverse_each.find`. I've found myself using this a surprising number of times, and have been surprised at its omission. That means either falling back to `reverse_each` or `rindex`. For context, here are a couple of examples of this in the wild: * [pry](https://github.com/pry/pry/blob/80816f596774d00afdc81a555724b0819bf26782/lib...) * [bundler](https://github.com/ruby/rubygems/blob/e4fd4ee3fad005fce1dbcbeffd47e7199243bc...) * [textbringer](https://github.com/shugo/textbringer/blob/738d318558045efc9d978e6b5616d2641a...) -- https://bugs.ruby-lang.org/
Issue #21678 has been updated by etienne (Étienne Barrié). Should we alias `detect` to also use that Array-specific faster implementation? ```console
[].method :detect => #<Method: Array(Enumerable)#detect(*)> [].method :find => #<Method: Array#find(*)>
----------------------------------------
Feature #21678: Enumerable#rfind
https://bugs.ruby-lang.org/issues/21678#change-115679
* Author: kddnewton (Kevin Newton)
* Status: Closed
----------------------------------------
I'd like to introduce `rfind` to enumerable, which would effectively be the same as `reverse_each.find`. I've found myself using this a surprising number of times, and have been surprised at its omission. That means either falling back to `reverse_each` or `rindex`.
For context, here are a couple of examples of this in the wild:
* [pry](https://github.com/pry/pry/blob/80816f596774d00afdc81a555724b0819bf26782/lib/pry/commands/edit.rb#L213)
* [bundler](https://github.com/ruby/rubygems/blob/e4fd4ee3fad005fce1dbcbeffd47e7199243bc42/bundler/lib/bundler/self_manager.rb#L146)
* [textbringer](https://github.com/shugo/textbringer/blob/738d318558045efc9d978e6b5616d2641a1b1305/lib/textbringer/modes/ruby_mode.rb#L271)
--
https://bugs.ruby-lang.org/
Issue #21678 has been updated by Eregon (Benoit Daloze). @etienne Yes, that seems clearly a good fix, could you do it? (I personally don't like `detect` but we should keep aliases consistent in performance and behavior) ---------------------------------------- Feature #21678: Enumerable#rfind https://bugs.ruby-lang.org/issues/21678#change-115690 * Author: kddnewton (Kevin Newton) * Status: Closed ---------------------------------------- I'd like to introduce `rfind` to enumerable, which would effectively be the same as `reverse_each.find`. I've found myself using this a surprising number of times, and have been surprised at its omission. That means either falling back to `reverse_each` or `rindex`. For context, here are a couple of examples of this in the wild: * [pry](https://github.com/pry/pry/blob/80816f596774d00afdc81a555724b0819bf26782/lib...) * [bundler](https://github.com/ruby/rubygems/blob/e4fd4ee3fad005fce1dbcbeffd47e7199243bc...) * [textbringer](https://github.com/shugo/textbringer/blob/738d318558045efc9d978e6b5616d2641a...) -- https://bugs.ruby-lang.org/
Issue #21678 has been updated by kddnewton (Kevin Newton). Is this an issue where you could have defined `Enumerable#find` and now it won't have overwritten `Array#find`? Should I revert that part of this patch? ---------------------------------------- Feature #21678: Enumerable#rfind https://bugs.ruby-lang.org/issues/21678#change-115694 * Author: kddnewton (Kevin Newton) * Status: Closed ---------------------------------------- I'd like to introduce `rfind` to enumerable, which would effectively be the same as `reverse_each.find`. I've found myself using this a surprising number of times, and have been surprised at its omission. That means either falling back to `reverse_each` or `rindex`. For context, here are a couple of examples of this in the wild: * [pry](https://github.com/pry/pry/blob/80816f596774d00afdc81a555724b0819bf26782/lib...) * [bundler](https://github.com/ruby/rubygems/blob/e4fd4ee3fad005fce1dbcbeffd47e7199243bc...) * [textbringer](https://github.com/shugo/textbringer/blob/738d318558045efc9d978e6b5616d2641a...) -- https://bugs.ruby-lang.org/
participants (5)
-
Eregon (Benoit Daloze) -
etienne -
kddnewton (Kevin Newton) -
matz (Yukihiro Matsumoto) -
nobu (Nobuyoshi Nakada)