From: merch-redmine@... Date: 2019-03-27T17:15:14+00:00 Subject: [ruby-core:92014] [Ruby trunk Feature#15730] Add map_with_index method Issue #15730 has been updated by jeremyevans0 (Jeremy Evans). jzakiya (Jabari Zakiya) wrote: > I was converting some Ruby code to Crystal on Rosetta Code and came across this Ruby snippet, > > ``` > arry.each_with_index.map{ |x,y| ......} > ``` > where ``arry`` is an array of integers. > > This wouldn't convert directly into Crystal (wouldn't compile). > Looking at their ``enumerables`` methods they have ``map_with_index``, and that works. > > ``` > arry.map_with_index{ |x,y| ......} > ``` > > I don't know how frequently in Ruby this method combination exits, but I suspect it's somewhat common. > I think this method makes a whole lot of logical sense, would optimize the concept, and makes reading code easier. > Anyway, thanks for any consideration. Enumerator#with_index already exists: ```ruby [1,3,5].map.with_index{ |x, i| (x+i)**2} => [1, 16, 49] ``` I believe the reason Enumerable#each_with_index is a separate method is because it was added before Enumerator#with_index. However, I don't think it makes sense to add more *_with_index methods. ---------------------------------------- Feature #15730: Add map_with_index method https://bugs.ruby-lang.org/issues/15730#change-77341 * Author: jzakiya (Jabari Zakiya) * Status: Open * Priority: Normal * Assignee: * Target version: ---------------------------------------- I was converting some Ruby code to Crystal on Rosetta Code and came across this Ruby snippet, ``` arry.each_with_index.map{ |x,y| ......} ``` where ``arry`` is an array of integers. This wouldn't convert directly into Crystal (wouldn't compile). Looking at their ``enumerables`` methods they have ``map_with_index``, and that works. ``` arry.map_with_index{ |x,y| ......} ``` I don't know how frequently in Ruby this method combination exits, but I suspect it's somewhat common. I think this method makes a whole lot of logical sense, would optimize the concept, and makes reading code easier. Anyway, thanks for any consideration. -- https://bugs.ruby-lang.org/ Unsubscribe: