I want to change the array (I use splice in this example, but it can be any operation that modifies the array) and returns the changed array - unlike slice , which returns the elements extracted from the array. I can do this easily by storing the block in an array as follows:
my $l = -> $a { splice($a,1,3,[1,2,3]); $a }; say (^6).map( { $_ < 4 ?? 0 !! $_ } ).Array;
How do I embed the block represented by $l in one expression? Obvious substitution does not work:
say (^6).map( { $_ < 4 ?? 0 !! $_ } ).Array.(-> $a { splice($a,1,3,[1,2,3]); $a }) Invocant requires a type object of type Array, but an object instance was passed. Did you forget a 'multi'?
Any suggestions?
source share