Project

General

Profile

Actions

Feature #21678

open

Enumerable#rfind

Feature #21678: Enumerable#rfind

Added by kddnewton (Kevin Newton) 22 days ago. Updated 18 days ago.

Status:
Open
Assignee:
-
Target version:
-
[ruby-core:123754]

Description

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:

Updated by matz (Yukihiro Matsumoto) 19 days ago Actions #2 [ruby-core:123782]

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.

Updated by kddnewton (Kevin Newton) 19 days ago Actions #3 [ruby-core:123790]

That makes sense! I'm totally fine with it just being on Array.

Actions

Also available in: PDF Atom