RosettaCodeData/Task/Flatten-a-list/Perl-6/flatten-a-list.pl6
2018-06-22 20:57:24 +00:00

7 lines
304 B
Raku

my @l = [[1], 2, [[3,4], 5], [[[]]], [[[6]]], 7, 8, []];
say .perl given gather @l.deepmap(*.take); # lazy recursive version
# Another way to do it is with a recursive function (here actually a Block calling itself with the &?BLOCK dynamic variable):
say { |(@$_ > 1 ?? map(&?BLOCK, @$_) !! $_) }(@l)