Project

General

Profile

Feature #15145

chained mappings proposal

Added by koenhandekyn (koen handekyn) about 2 years ago. Updated about 2 years ago.

Status:
Open
Priority:
Normal
Assignee:
-
Target version:
-
[ruby-core:89122]

Description

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

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)

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

proposal to be functional equivalent to

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

Also available in: Atom PDF