Course of Raku / Advanced / Control flow / gather and take

Quiz — gather

What does the following program print?

my @r = gather for 1..6 {
    take $_ if $_ %% 3;
};

say @r;
1[3 6]
0[1 2 3 4 5 6]
0[3]
0[]

gather collects only the values that take is actually called on. The guard $_ %% 3 is true only for 3 and 6, so just those two are taken, giving [3 6].

Course navigation

Solution: Gather until full   |   Statement prefixes 🆕