Issue #8987 has been updated by Matthew Kerwin.


 On 31 January 2014 15:48, SASADA Koichi <ko1 / atdot.net> 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/

----------------------------------------
Feature #8987: map/collect extension which handles arguments
https://bugs.ruby-lang.org/issues/8987#change-44851

* 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/