Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@dogbert17
Created June 14, 2016 19:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dogbert17/06d296160772002c93029bd90b1d6874 to your computer and use it in GitHub Desktop.
Save dogbert17/06d296160772002c93029bd90b1d6874 to your computer and use it in GitHub Desktop.
Attempt to document Baggy.pick
=head2 method pick
Defined as:
multi method pick(Baggy:D:) returns Any
multi method pick(Baggy:D: $count) returns Seq:D
Like an ordinary list L<pick|/type/List#routine_pick>, but returns keys
of the invocant weighted by their values, as if the keys were replicated
the number of times indicated by the corresponding value and then list
pick used. The underlying metaphor for picking is that you're pulling
colored marbles out a bag. (For "picking with replacement" see
L<roll|#method roll> instead). If C<*> is passed as C<$count>, or C<$count> is
greater than or equal to the L<total|#method total> of the invocant, then
C<total> elements from the invocant are returned in a random sequence.
Note that each C<pick> invocation maintains its own private state and has
no effect on subsequent C<pick> invocations.
my $breakfast = bag <eggs bacon bacon bacon>;
say $breakfast.pick; # eggs
say $breakfast.pick(2); # (eggs bacon)
say $breakfast.total; # 4
say $breakfast.pick(*); # (bacon bacon bacon eggs)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment