Course of Raku / Functional, concurrent, reactive, and web programming / Functional programming / Iterators / Exercises / Gather the multiples of three
Solution: Gather the multiples of three
Here is a possible solution to the task.
Code
my @threes = gather {
for 1..15 {
take $_ if $_ %% 3;
}
}
say @threes;🦋 You can find the source code in the file gather-evens.raku.
Output
[3 6 9 12 15]Comments
The loop visits every number, but
takeruns only when$_ %% 3is true.So only the multiples of three are collected into the list.