See Original text in context
multi method pickpairs(Baggy: --> Pair)multi method pickpairs(Baggy: --> Seq)
Returns a Pair
or a Seq
of Pair
s depending on the version of the method being invoked. Each Pair
returned has an element of the invocant as its key and the element's weight as its value. The elements are 'picked' without replacement. If *
is passed as $count
, or $count
is greater than or equal to the number of elements of the invocant, then all element/weight Pair
s from the invocant are returned in a random sequence.
Note that each pickpairs
invocation maintains its own private state and has no effect on subsequent pickpairs
invocations.
my = bag <eggs bacon bacon bacon>;say .pickpairs; # OUTPUT: «eggs => 1»say .pickpairs(1); # OUTPUT: «(bacon => 3)»say .pickpairs(*); # OUTPUT: «(eggs => 1 bacon => 3)»
See Original text in context
multi method pickpairs(Setty: --> Pair)multi method pickpairs(Setty: --> Seq)
Returns a Pair
or a Seq
of Pair
s depending on the candidate of the method being invoked. Each Pair
returned has an element of the invocant as its key and True
as its value. In contrast to grabpairs, the elements are 'picked' without replacement.
If *
is passed as $count
, or $count
is greater than or equal to the number of elements of the invocant, then all element/True
Pair
s from the invocant are returned in a random sequence; i.e. they are returned shuffled;
Note that each pickpairs
invocation maintains its own private state and has no effect on subsequent pickpairs
invocations.
my = set (4, 2, 3);say .pickpairs; # OUTPUT: «4 => True»say .pickpairs(1); # OUTPUT: «(3 => True)»say .pickpairs(*); # OUTPUT: «(2 => True 4 => True 3 => True)»