Skip to content

Commit dc7f8a7

Browse files
authored
Merge pull request #2794 from lukasvalle/master
Example for the "hyper for" and the "race for" statements.
2 parents 46f4f13 + 95892c1 commit dc7f8a7

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

doc/Language/control.pod6

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -531,6 +531,25 @@ Assigning C<Empty> will effectively undefine an Array, using C<for> over an
531531
undefined array will not even enter the loop, as shown, effectively behaving in
532532
the same way as above when C<Empty> was used directly.
533533
534+
535+
With C<hyper> and C<race> the for loop is potentially iterated in parallel.
536+
See also the documentaion for C<hyper> and C<race> in class L<Map|/type/Map>.
537+
538+
539+
=for code
540+
my $primes_h = hyper for ^10_000 -> $number { $number if $number.is-prime };
541+
say $primes_h.elems; # OUTPUT: «1229␤»
542+
say $primes_h.tail: 5; # OUTPUT: «(9931 9941 9949 9967 9973)␤»
543+
544+
with C<hyper> the order of elements is preserved.
545+
546+
=for code
547+
my $primes_r = race for ^10_000 -> $number { $number if $number.is-prime };
548+
say $primes_r.elems; # OUTPUT: «1229␤»
549+
550+
Unlike hyper, C<race> does not preserve the order of elements.
551+
552+
534553
=head1 X<gather/take|control flow,gather take>
535554
536555
X<|lazy list,gather>X<|lazy list,take>

0 commit comments

Comments
 (0)