Course of Raku / Functional, concurrent, reactive, and web programming / Functional programming / Iterators / Exercises / Gather the cubes
Solution: Gather the cubes
Here is a possible solution to the task.
Code
my @cubes = gather {
take $_ ** 3 for 1..4;
}
say @cubes;🦋 You can find the source code in the file gather-squares.raku.
Output
[1 8 27 64]Comments
The
takeruns once for each number, contributing its cube ($_ ** 3).The
gatherblock evaluates to the list of all taken values.