Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Perl 6 List Concatenation without Slip?

In Perl the , operator can be used to concatenate Lists; however, Perl 6 does not flatten Lists in this context resulting in a List of two Lists. Concatenating the Lists requires using |, the slip operator.

my @a = <a b c>;
my @b = <d e f>;
my @ab = |@a, |@b;

Is there any shorthand for this operation?

like image 510
J Hall Avatar asked Jan 02 '16 16:01

J Hall


1 Answers

You can use the "flat" sub for this:

my @a  = <a b c>;
my @b  = <d e f>;
my @ab = flat @a, @b;
say @ab.perl; #> ["a", "b", "c", "d", "e", "f"]
my @abf = (@a, @b).flat;
say @abf.perl; #> ["a", "b", "c", "d", "e", "f"]
like image 82
timotimo Avatar answered Oct 10 '22 03:10

timotimo