Course of Raku / Advanced / Containers / Ordered containers / Exercises / Flatten the parts
Solution: Flatten the parts
Here is a possible solution to the task.
Code
my @first = 1, 2;
my @second = 3, 4, 5;
my @all = flat(@first, @second);
say @all;
say @all.elems;🦋 You can find the source code in the file flatten-the-parts.raku.
Output
[1 2 3 4 5]
5Comments
Writing
my @all = @first, @secondwould not give a flat array — it would create a nested array of two arrays,[[1 2] [3 4 5]].The
flatroutine merges the elements of both arrays into a single flat sequence, which is then stored in@all. The result has five elements.