Consider
.say for (1,2,2).rotor(2=>-1).map( -> ($a, $b) { $a - $b })
which works as expected. However,
.say for (1,2,2).pairs.rotor(2=>-1).map( -> ($a, $b) { $a.value - $b.value })
throws
Too few positionals passed to '<anon>'; expected 2 arguments but got 0 in sub-signature
Is this a bug or am I missing something?
This is Rakudo Star version 2019.03.1 built on MoarVM version 2019.03 implementing Perl 6.d.
We can also destructure a list, for example, or even a set. You're unlikely to want to perform a destructuring assignment with a set, however, since the order is not guaranteed, and we therefore end up with variables we don't really know the values of.
If you want to skip a variable or element in destructuring declarations, then you can use underscore instead of the variable name. As a result, Kotlin won't call the component function for those unused variables. For example, we need only the 1st, 5th and 6th elements in the list.
To destructure an array in JavaScript, we use the square brackets [] to store the variable name which will be assigned to the name of the array storing the element.
It is taking the Pair
as a Capture
, thus turning the Pair
into a named argument:
$ raku -e '(a => 42, b => 666).map: -> |c { dd c }'
\(:a(42))
\(:b(666))
In your example, it then doesn't pass any positional arguments, thus causing the observed execution error.
jnthn++ for pointing this out.
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