A basic challenge of iterators
Write a function (like map) that processes all of the elements of a List.
map generally acts like a filter in a pipeline.
sub mymap(@list, &block) {
my $i = 0;
my @result;
while $i < @list.elems {
push @result, &block(@list[$i]);
$i = $i + 1;
}
@result;
}
As written, this function is eager (okay for this example)
- Why not just use a for loop instead of while?
- In Perl 6, map and for are equivalent