Project

General

Profile

Actions

Feature #10549

open

Deprecate each_with_index and each_with_object in favor of with_index and with_object

Added by danielmorrison (Daniel Morrison) almost 10 years ago. Updated 8 months ago.

Status:
Assigned
Target version:
-
[ruby-core:66493]

Description

I wonder if we can deprecate each_with_index and each_with_object and fully recommend with_index and with_object instead.

I personally like the shorter forms because they hint that they can be used with more methods than simply each. People don't need to ask if there's a map_with_index method, they can just try chaining it the same way and it works! I realized this when teaching new Rubyists, because they often ask those questions.

There is a negligible performance hit.

Lots of code uses each_with_index but it is a one-character change to use each.with_index instead.

Forgive me if this has been brought up recently, but I couldn't find any discussion on it.

Updated by trans (Thomas Sawyer) almost 10 years ago

If Functors* (https://bugs.ruby-lang.org/issues/6594) could be built into the language proper, then what you suggest should be possible with essentially no performance penalties at all.

(* Not to be confused with the Haskell concept.)

Actions #2

Updated by naruse (Yui NARUSE) almost 7 years ago

  • Target version deleted (2.2.0)
Actions #3

Updated by hsbt (Hiroshi SHIBATA) over 3 years ago

  • Tracker changed from Misc to Feature
Actions #4

Updated by hsbt (Hiroshi SHIBATA) 8 months ago

  • Status changed from Open to Assigned
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0