Apply a callback to an array: Difference between revisions
Content added Content deleted
Underscore (talk | contribs) (Added Perl 6.) |
|||
Line 870: | Line 870: | ||
# filter an array |
# filter an array |
||
my @e = grep { $_ % 2 == 0 } @a; # @e is now (2, 4)</lang> |
my @e = grep { $_ % 2 == 0 } @a; # @e is now (2, 4)</lang> |
||
=={{header|Perl 6}}== |
|||
{{works with|Rakudo|#21 "Seattle"}} |
|||
<lang perl6>my $function = { 2*$^x + 3 }; |
|||
my @array = 1 .. 5; |
|||
.say for map $function, @array; |
|||
.say for @array.map($function); |
|||
for @array { |
|||
say $function($_); |
|||
}</lang> |
|||
=={{header|PHP}}== |
=={{header|PHP}}== |