Logo

Programming-Idioms

History of Idiom 189 > diff from v12 to v13

Edit summary for version 13 by andrezgz:
[Perl] Adding demo

Version 12

2019-09-27, 23:27:30

Version 13

2019-09-27, 23:29:08

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
Extra Keywords
map apply
Code
my @y = map { T($_) } grep { P($_) } @x;
Code
my @y = map { T($_) } grep { P($_) } @x;
Comments bubble
$_ inside grep block represents each element e of array x
Comments bubble
$_ inside grep block represents each element e of array x
Demo URL
http://codepad.org/BbpkDumF