Skip to content
Permalink
Browse files

Adds eager, refs #534 #2034

  • Loading branch information...
JJ committed Apr 15, 2019
1 parent 4ef6886 commit c379f5b07d5b4247c44f76e80bfb50a04cce5399
Showing with 18 additions and 4 deletions.
  1. +18 −4 doc/Language/statement-prefixes.pod6
@@ -32,12 +32,26 @@ such as calling the C<.eager> method on it.
=for code
my @array = lazy { (^3).map( *² ) };
say @array; # OUTPUT: «[...]»
say @array.eager; # OUTPUT: «[0 1 4]␤»
say @array.eager; # OUTPUT: «[0 1 4]␤»
This prefix can also be used
L<in front of C<gather>|/language/control#gather/take> to make the inner
statements behave lazily.
This prefix can also be used L<in front of
C<gather>|/language/control#gather/take> to make the inner statements behave
lazily; in general, any set of statements that returns a value will be lazified
using this.
=head2 X<C<eager>|eager (statement prefix)>
The C<eager> statement prefix will eagerly return the result of the statements
behind, throwing away laziness and returning the result.
=for code
my $result := eager gather { for 1..3 { say "Hey"; take $_² } };
say $result[0]; # OUTPUT: «Hey␤Hey␤Hey␤1␤»
C<gather> is L<implictly lazy when bound to a scalar|/syntax/gather%20take>.
However, with C<eager> as a statement prefix it will run all three iterations in
the loop, as shown by the printed "Hey", even if we are just requesting the
first one in a row.
=end pod

0 comments on commit c379f5b

Please sign in to comment.
You can’t perform that action at this time.