What's the shortest way to flat a multidimensional array?
Here's some examples of what I mean:
# 2D array
my @a = [1,2],[3,4];
say @a».Slip.flat; # prints (1 2 3 4)
# 3D array
my @b = [[1,2],[3,4]],[[5,6],[7,8]];
say @b».Slip».flat».Slip.flat; # prints (1 2 3 4 5 6 7 8)
# but needs to know how many dimensions
# there are to flatten
Is it possible to recursively flatten an array of arrays such as @b
without writing a sub which recursively descends into it or having any knowledge of the number of its dimensions?
I'm asking this because I trust the compiler (now or in a future implementation) to be able to optimize more an operator-based solution than a sub.