Depending on the exact semantics you are looking for, Bag operations can only be a ticket:
my \L = 3, 1, 4, 1, 5, 9, 2, 6; my \M = 9, 7, 1, 2, 1, 1; .put with L.Bag ∩ M.Bag;
displayed:
9 1(2) 2
This is a Bag line containing three keys '9' , '1' and '2' , whose corresponding values (number of repetitions) are integers 1 , 2 and 1 .
To get Perl 6 to create a list from a bag, each key repeated the number of times indicated by its associated value, use the .kxxv method:
.kxxv.put with L.Bag ∩ M.Bag;
displayed:
9 1 1 2
(The mnemonic for the kxxv method is that it is k for the “key”, then xx by analogy with xx and finally v for the “value.” This makes sense if you think about it.)
But perhaps the bag will not do. For example, perhaps the order of the elements in the result matters - do you need 9 1 2 1 and not 9 1 1 2 ? I will continue this answer if the bag is not suitable for the right path.
raiph source share