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?
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"]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With