@@ -29,7 +29,31 @@ L<Mixy>.
29
29
30
30
= head2 method roll
31
31
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)
33
57
34
58
= head2 method classify-list
35
59
0 commit comments