Skip to content

Commit d0e9368

Browse files
committed
Elaborate a bit more about (Bag|BagHash).pickpairs
1 parent 64c4899 commit d0e9368

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

S32-setting-library/Containers.pod

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1233,23 +1233,24 @@ rather than a constructor.)
12331233

12341234
multi method pick ( $bag: Int $num = 1 --> Any )
12351235
multi method pick ( $bag: Whatever --> Any )
1236-
multi method pickpairs ( $bag: Int $num = 1 --> Any )
1237-
multi method pickpairs ( $bag: Whatever --> Any )
1236+
multi method pickpairs ( $bag: Int $num = 1 --> Pairs )
1237+
multi method pickpairs ( $bag: Whatever --> Pairs )
12381238

12391239
Like an ordinary list C<pick>, but returns keys of the bag weighted by
12401240
values, as if the keys were replicated the number of times indicated
1241-
by the corresponding value and then list pick used. C<BagHash> is the
1241+
by the corresponding value and then list pick used. The C<pickpairs> method
1242+
does the same, except it returns both key and value. C<BagHash> is the
12421243
mutable form of C<Bag>. A C<Bag> responds to hash operators as
12431244
if it were a C<Hash of UInt>.
12441245

12451246
The underlying metaphor for picking is that you're pulling colored
12461247
marbles out a bag. (For "picking with replacement" see C<roll> instead.)
1247-
Picking require tracking the temporary state, so the immutable C<Bag> is copied to
1248-
a temporary private C<BagHash>, and the picks are made from that
1248+
Picking require tracking the temporary state, so the immutable C<Bag> is
1249+
copied to a temporary private C<BagHash>, and the picks are made from that
12491250
using the corresponding C<.grab> or C<.grabpairs> method (see below).
12501251

1251-
Each C<.pick> invocation maintains its own private state and has no
1252-
effect on subsequent C<.pick> invocations.
1252+
Each C<.pick>/C<.pickpairs> invocation maintains its own private state and
1253+
has no effect on subsequent C<.pick>/C<.pickpairs> invocations.
12531254

12541255
=item roll
12551256

0 commit comments

Comments
 (0)