Issue #10254 has been updated by Andrew Vit.


`nested_map` makes sense since there is a `flat_map`. This is similar but different:

~~~
[[[1, 2], [3, 4]], [[5, 6]]].flatten(2).map{|e| e + 1} #=> [2, 3, 4, 5, 6, 7]
~~~

----------------------------------------
Feature #10254: Array#each and Array#map for nested arrays
https://bugs.ruby-lang.org/issues/10254#change-48980

* Author: Tsuyoshi Sawada
* Status: Feedback
* Priority: Normal
* Assignee: 
* Category: 
* Target version: 
----------------------------------------
In order to allow iteration over elements of arrays nested within an array, I propose to pass `Array#each` and `Array#map` an optional argument that expresses the depth to iterate over.

Conventionally, iterating over nested elements requires nested `each` or `map`:

    [[1, 2], [3, 4], [5, 6]].map{|a| a.map{|e| e + 1}} #=> [[2, 3], [4, 5], [6, 7]]
    [[[1, 2], [3, 4]], [[5, 6]]].map{|a| a.map{|a| a.map{|e| e + 1}}} #=> [[[2, 3], [4, 5]], [[6, 7]]]

With the proposed optional argument, this would be done by:

    [[1, 2], [3, 4], [5, 6]].map(1){|e| e + 1} #=> [[2, 3], [4, 5], [6, 7]]
    [[[1, 2], [3, 4]], [[5, 6]]].map(2){|e| e + 1} #=> [[[2, 3], [4, 5]], [[6, 7]]]

Absence of the parameter should be understood as the parameter being defaulted to `0`.

    [1, 2, 3, 4, 5, 6].map{|e| e + 1} #=> [2, 3, 4, 5, 6, 7]
    [1, 2, 3, 4, 5, 6].map(0){|e| e + 1} #=> [2, 3, 4, 5, 6, 7]




-- 
https://bugs.ruby-lang.org/