Skip to content

Commit 510d6a7

Browse files
author
Jan-Olof Hendig
committed
Added docs for Baggy.roll. Most text from S32
1 parent db08426 commit 510d6a7

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

doc/Type/Baggy.pod

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,31 @@ L<Mixy>.
2929
3030
=head2 method roll
3131
32-
=comment TODO
32+
Defined as:
33+
34+
multi method roll(Baggy:D:) returns Any:D
35+
multi method roll(Baggy:D: $count) returns Seq:D
36+
37+
Like an ordinary list L<roll|/type/List/#routine_roll>, but returns keys of the invocant weighted
38+
by their values, as if the keys were replicated the number of times indicated
39+
by the corresponding value and then list roll used. The underlying
40+
metaphor for rolling is that you're throwing C<$count> dice that are
41+
independent of each other, which (in bag terms) is equivalent to picking
42+
a colored marble out your bag and then putting it back, and doing this
43+
C<$count> times. In dice terms, the number of marbles corresponds to the
44+
number of sides, and the number of marbles of the same color corresponds
45+
to the number of sides with the same color. (For "picking without replacement"
46+
see L<pick|#method pick> instead).
47+
48+
If C<*> is passed to C<$count>, returns a lazy, infinite sequence of randomly
49+
chosen elements from the invocant.
50+
51+
my $breakfast = bag <eggs bacon bacon bacon>;
52+
say $breakfast.roll; # bacon
53+
say $breakfast.roll(3); # (bacon eggs bacon)
54+
55+
my $random_dishes := $breakfast.roll(*);
56+
say $random_dishes[^5]; # (bacon eggs bacon bacon bacon)
3357
3458
=head2 method classify-list
3559

0 commit comments

Comments
 (0)