Skip to content

Commit 0ee3245

Browse files
committed
Add documentation for List.invert
1 parent 880edf3 commit 0ee3245

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

doc/Type/List.pod6

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,20 @@ values, i.e. the direct opposite to L<pairs|/type/List#routine_pairs>.
194194
195195
say <a b c>.antipairs; # OUTPUT: «(a => 0 b => 1 c => 2)␤»
196196
197+
=head2 routine invert
198+
199+
Defined as:
200+
201+
method invert(List:D: --> Seq:D)
202+
203+
Assumes every element of the List is a C<Pair>. Returns all elements as a
204+
L<Seq|/type/Seq> of C<Pair>s where the keys and values have been exchanged.
205+
If the value of a C<Pair> is an C<Iterable>, then it will expand the values
206+
of that C<Iterable> into separate pairs.
207+
208+
my $l = List.new('a' => (2, 3), 'b' => 17);
209+
say $l.invert; # OUTPUT: «(2 => a 3 => a 17 => b)␤»
210+
197211
=head2 routine join
198212
199213
Defined as:

0 commit comments

Comments
 (0)