Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Document laziness in traps
There are several bug reports on RT that aren't bugs but lazy maps, which warrants adding this in traps.
  • Loading branch information
zoffixznet committed Jul 10, 2016
1 parent e544a61 commit d1533bb
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions doc/Language/traps.pod6
Expand Up @@ -303,6 +303,35 @@ Finally, note that, currently, when declaring the functions whitespace
may be used between a function or method name and the parentheses
surrounding the parameter list without problems.
=head1 Lazy Evaluation
Many constructs in Perl 6 evaluate lazily, performing work only when a
value is needed. Among others, these include C<.grep> and C<.map>. They
won't perform the work unless you actually use the values. For example,
this C<.map> does not actually print anything because we don't use its result:
for ^3 {
^10 .map: *.say;
};
say 42;
# OUTPUT:
# 42
To fix that, you should use L<eager|/routine/eager> to avoid laziness or
rewrite the loop using a C<for> instead of C<map>:
for ^3 {
^10 .map(*.say).eager;
};
say 42;
# OR
for ^3 {
.say for ^10;
};
say 42;
=end pod

# vim: expandtab shiftwidth=4 ft=perl6

0 comments on commit d1533bb

Please sign in to comment.