Skip to content

Commit 79b1cce

Browse files
author
Jan-Olof Hendig
committed
Added missing info and example to the docs for Map.invert
1 parent 70fc547 commit 79b1cce

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

doc/Type/Map.pod

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,10 @@ Defined as:
130130
131131
method antipairs(Map:D:) returns Seq:D
132132
133+
Usage:
134+
135+
MAP.antipairs
136+
133137
Returns all keys and their respective values as a L<Seq|/type/Seq> of C<Pair>s
134138
where the keys and values have been exchanged, i.e. the opposite of method
135139
L<pairs|#method_pairs>. Unlike the L<invert|#method_invert> method, there is
@@ -142,13 +146,19 @@ no attempt to expand list values into multiple pairs.
142146
143147
Defined as:
144148
145-
method invert(Map:D:) returns List:D
149+
method invert(Map:D:) returns Seq:D
146150
147151
Usage:
148152
149153
MAP.invert
150154
151-
Returns a list of pairs, but with key and value exchanged.
155+
Returns all keys and their respective values as a L<Seq|/type/Seq> of C<Pair>s
156+
where the keys and values have been exchanged. The difference between C<invert>
157+
and L<antipairs|#method_antipairs> is that C<invert> expands list values into
158+
multiple pairs.
159+
160+
my $m = Map.new('a' => (2, 3), 'b' => 17);
161+
say $m.invert; # (2 => a 3 => a 17 => b)
152162
153163
=head2 method kv
154164

0 commit comments

Comments
 (0)