Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Added docs for Baggy.grabpairs
  • Loading branch information
Jan-Olof Hendig committed Jun 16, 2016
1 parent 4f52547 commit 5299b4f
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion doc/Type/Baggy.pod
Expand Up @@ -39,7 +39,30 @@ probabilities stay consistent through subsequent C<grab> operations.
=head2 method grabpairs
=comment TODO
Defined as:
multi method grabpairs(Baggy:D:) returns Any
multi method grabpairs(Baggy:D: $count) returns List:D
Returns a C<Pair> or a C<List> of C<Pair>s depending on the version of the method
being invoked. Each C<Pair> returned has an element of the invocant as its key and the
elements weight as its value. Unlike L<pickpairs>, it works only on mutable structures,
e.g. L<BagHash|/type/BagHash>. Use of C<grabpairs> on 'an immutable structure results in
an C<X::Immutable> exception. If C<*> is passed as C<$count>, or C<$count> is greater
than or equal to the number of L<elements|#method elems> of the invocant, then all
element/weight C<Pair>s from the invocant are returned in a random sequence.
What makes C<grabpairs> different from L<pickpairs|#method pickpairs> is that the
'grabbed' elements are in fact removed from the invocant.
my $breakfast = (eggs => 2, bacon => 3).BagHash;
say $breakfast.grabpairs; # bacon => 3
say $breakfast; # BagHash.new(eggs(2))
say $breakfast.grabpairs(1); # (eggs => 2)
say $breakfast.grabpairs(*); # []
my $diet = ('eggs' => 2, 'bacon' => 3).Bag;
say $diet.grabpairs; # throws X::Immutable exception
=head2 method pick
Expand Down

0 comments on commit 5299b4f

Please sign in to comment.