The repeated
method takes a function as an argument for normalizing the elements before finding out which ones are repeated. However, I can't seen to make it work with values
. For instance:
%(:a(3),:b(3),:c(2)).repeated( as=> *.values ).say
Returns an empty list, while I was expecting the pairs :a(3) and :b(3), same as
%(:a(3),:b(3),:c(2)).repeated( as=> .values ).say
In this case, for instance, it seems to work as expected:
(3+3i, 3+2i, 2+1i).unique(as => *.re).say # OUTPUT: «(3+3i 2+1i)»
Any idea of what I'm missing here?
.values
is a method for returning all of the values of a container.
Since it is a List method, if you call it on a singular value it pretends it is a List containing only that value.
say 5.values.perl;
# (5,)
The as
named parameter of .repeated
gets called on all of the singular values.
%(:a(3),:b(3),:c(2)).repeated( as=> *.perl.say );
# :a(3)
# :b(3)
# :c(2)
So by giving it the *.values
lambda, it is effectively not doing anything useful.
The method you were looking for is .value
. Which is a method on a Pair.
%(:a(3),:b(3),:c(2)).repeated( as=> *.value ).say
# (a => 3)
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