Logo

Programming-Idioms

History of Idiom 189 > diff from v22 to v23

Edit summary for version 23 by steenslag:
[Ruby] added comment

Version 22

2019-12-28, 02:52:32

Version 23

2019-12-28, 02:54:27

Idiom #189 Filter and transform list

Produce a new list y containing the result of function T applied to all elements e of list x that match the predicate P.

Idiom #189 Filter and transform list

Produce a new list y containing the result of function T applied to all elements e of list x that match the predicate P.

Extra Keywords
map apply satisfy
Extra Keywords
map apply satisfy
Code
y = x.filter_map{|e| t(e) if p(e)}
Code
y = x.filter_map{|e| t(e) if p(e)}
Comments bubble
filter_map is available for enumerables since Ruby 2.7.