Skip to content

Commit 0a5be13

Browse files
committed
Example for the hyper for and the race for statements.
1 parent 7b9d54f commit 0a5be13

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

doc/Language/control.pod6

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -535,6 +535,27 @@ Assigning C<Empty> will effectively undefine an Array, using C<for> over an
535535
undefined array will not even enter the loop, as shown, effectively behaving in
536536
the same way as above when C<Empty> was used directly.
537537
538+
539+
With C<hyper> and C<race> the for loop is potentially iterated in parallel.
540+
See also the documentaion for C<hyper> and C<race> in class L<Map|/type/Map>.
541+
542+
543+
=for code
544+
my $primes_h = hyper for ^10_000 -> $number { $number if $number.is-prime };
545+
say $primes_h.elems;
546+
say $primes_h.tail: 5; # OUTPUT: (9931 9941 9949 9967 9973)
547+
548+
with C<hyper> the order of elements is preserved.
549+
550+
=for code
551+
my $primes_r = race for ^10_000 -> $number { $number if $number.is-prime };
552+
say $primes_r.elems;
553+
say $primes_r.tail: 5; # OUTPUT: (9871 9883 9887 9901 9907)
554+
555+
Unlike hyper, C<race> does not preserve the order of elements.
556+
557+
558+
538559
=head1 X<gather/take|control flow,gather take>
539560
540561
X<|lazy list,gather>X<|lazy list,take>

0 commit comments

Comments
 (0)