Project

General

Profile

Actions

Feature #15730

closed

Add map_with_index method

Added by jzakiya (Jabari Zakiya) about 5 years ago. Updated about 5 years ago.

Status:
Closed
Assignee:
-
Target version:
-
[ruby-core:92013]

Description

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.

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0