From: sowieso@... Date: 2014-01-31T08:19:50+00:00 Subject: [ruby-core:60381] [ruby-trunk - Feature #8987] map/collect extension which handles arguments Issue #8987 has been updated by So Wieso. Matthew Kerwin wrote: > On 31 January 2014 15:48, SASADA Koichi wrote: > > > p [1, 2, 3, 4].map(&4.method(:+)) #=> [5, 6, 7, 8] > > p [1, 2, 3, 4].map(&��{|x| 4+x}) #=> [5, 6, 7, 8] > > p [1, 2, 3, 4].map(&��(4, :+)) #=> [5, 6, 7, 8] > > p [1, 2, 3, 4].map(&��("4+")) #=> [5, 6, 7, 8] > > p [1, 2, 3, 4].map(&��{4+_}) #=> [5, 6, 7, 8] (doesn't run) > > > > Are any of these actually better than: > > p [1, 2, 3, 4].map{|x| 4+x } > > ? > > > -- > Matthew Kerwin > http://matthew.kerwin.net.au/ Actually I believe the most readable form would be `p [1,2,3,4].map{ 4 + _ } # when there is no |���|, set block params to _ ` Many blocks in realworld-code are so easy, that it is really a barrier to have to think about a name, and therefore one uses often non-verbose names like you used x. Where is the point in being forced to think of a name, when you don't set the name to something meaningful. I guess this was the idea why the to_proc convention was introduced. The problem with it is, that it is really limiting because you cannot use parameters (and the presence of a parameter doesn't necessarily make problems so complex to justify a name). ---------------------------------------- Feature #8987: map/collect extension which handles arguments https://bugs.ruby-lang.org/issues/8987#change-44856 * Author: So Wieso * Status: Open * Priority: Normal * Assignee: * Category: core * Target version: current: 2.2.0 ---------------------------------------- Please consider extending map/collect by allowing additional arguments to be passed to proc, like: A: [1,2,3,4].map :+, 4 and/or B: [1,2,3,4].map 4, &:+ => [5, 6, 7, 8] Variant A is probably more readable. Variant B is more versatile (allows arbitrary arguments to be passed to block). ---Files-------------------------------- mappi.rb (410 Bytes) -- http://bugs.ruby-lang.org/