From: matz@... Date: 2014-09-18T16:33:53+00:00 Subject: [ruby-core:65110] [ruby-trunk - Feature #10254] [Feedback] Array#each and Array#map for nested arrays Issue #10254 has been updated by Yukihiro Matsumoto. Status changed from Open to Feedback It should be separated in different method, e.g. #nested_map in my opinion. Matz. ---------------------------------------- Feature #10254: Array#each and Array#map for nested arrays https://bugs.ruby-lang.org/issues/10254#change-48967 * 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/