Created
June 16, 2016 19:17
-
-
Save dogbert17/0f5a38acd1c385629d604dd480398b82 to your computer and use it in GitHub Desktop.
Attempt to document method grabpairs in role Baggy
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| =head2 method grabpairs | |
| 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.grabpairs(1); # (eggs => 2) | |
| say $breakfast.grabpairs(*); # [] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment