[ruby-core:92026] [Ruby trunk Feature#15730] Add map_with_index method

From: matz@...
Date: 2019-03-28 01:19:32 UTC
List: ruby-core #92026
Issue #15730 has been updated by matz (Yukihiro Matsumoto).

Status changed from Open to Closed

Use `map.with_index`.

Matz.


----------------------------------------
Feature #15730: Add map_with_index method
https://bugs.ruby-lang.org/issues/15730#change-77351

* Author: jzakiya (Jabari Zakiya)
* Status: Closed
* 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: <mailto:ruby-core-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>

In This Thread

Prev Next