Project

General

Profile

Feature #15145

Updated by koenhandekyn (koen handekyn) over 5 years ago

propsal, have map accept array of method references to make chained mapping simpler    with suggestion to implement it to behave like the &. operator so that intermediate nil values just ripple through as nil values 

 proposal allow 

 ~~~ ruby 
 collection.map(&:instrument, &:issuer, &:name) 
 ~~~ 

 implementation is trivial  

 this as a conceptual alternative to (with important remark is that if first or second mapping returns nil values the above code will break, forcing a much more verbose notation) 

 ~~~ ruby 
 collection.map(&:instrument).map(&:issuer).map(&:name) 
 ~~~ 

 proposal to be functional equivalent to 

 ~~~ ruby 
 collection.map { |e| e&.instrument }.map { |e| e&.issuer }.map { |e| e&.name } 
 ~~~ 


 

 proposal allow 

 ~~~ ruby 
 collection.map(&:instrument, &:issuer, &:name) 
 ~~~ 

 implementation is trivial  

Back