Skip to content

Commit f134089

Browse files
author
Jan-Olof Hendig
committed
Added docs for Baggy.pick
1 parent 2f21131 commit f134089

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

doc/Type/Baggy.pod

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,29 @@ L<Mixy>.
2121
2222
=head2 method pick
2323
24-
=comment TODO
24+
Defined as:
25+
26+
multi method pick(Baggy:D:) returns Any
27+
multi method pick(Baggy:D: $count) returns Seq:D
28+
29+
Like an ordinary list L<pick|/type/List#routine_pick>, but returns keys
30+
of the invocant weighted by their values, as if the keys were replicated
31+
the number of times indicated by the corresponding value and then list
32+
pick used. The underlying metaphor for picking is that you're pulling
33+
colored marbles out a bag. (For "picking with replacement" see
34+
L<roll|#method roll> instead). If C<*> is passed as C<$count>, or C<$count> is
35+
greater than or equal to the L<total|#method total> of the invocant, then
36+
C<total> elements from the invocant are returned in a random sequence.
37+
38+
Note that each C<pick> invocation maintains its own private state and has
39+
no effect on subsequent C<pick> invocations.
40+
41+
my $breakfast = bag <eggs bacon bacon bacon>;
42+
say $breakfast.pick; # eggs
43+
say $breakfast.pick(2); # (eggs bacon)
44+
45+
say $breakfast.total; # 4
46+
say $breakfast.pick(*); # (bacon bacon bacon eggs)
2547
2648
=head2 method pickpairs
2749

0 commit comments

Comments
 (0)