@@ -197,25 +197,25 @@ of the invocant.
197
197
198
198
Defined as:
199
199
200
- method invert(Pair:D:)
200
+ method invert(Pair:D: --> Seq:D )
201
201
202
- Returns a new C < Pair > object with key and value exchanged, just like
203
- L < antipair|/type/Pair#method_antipair > , unless the value of the invocant does
204
- the L < Iterable|/type/Iterable > role. In the latter case an C < Iterable > structure
205
- of C < Pair > s is returned since C < invert > expands iterable values into multiple
206
- pairs.
202
+ Returns a L < Seq > . If the C < .value > of the invocant is I < NOT > an
203
+ L < Iterable|/type/Iterable > , the L < Seq > will contain a single L < Pair > whose
204
+ C < .key > is the C < .value > of the invocant and whose C < .value > is the C < .key > of
205
+ the invocant:
207
206
208
- my Pair $p1 = (6 => 'Perl');
209
- say $p1.invert; # OUTPUT: «Perl => 6»
210
- say $p1.invert.WHAT; # OUTPUT: «(Pair)»
207
+ :foo<bar>.invert.perl.say; # OUTPUT: «(:bar("foo"),).Seq»
211
208
212
- my Pair $p2 = ('Perl' => (5, 6));
213
- say $p2.invert; # OUTPUT: «(5 => Perl 6 => Perl)»
214
- say $p2.invert.WHAT; # OUTPUT: «(List)»
209
+ If invocant's C < .value > I < is > an L < Iterable|/type/Iterable > , the returned L < Seq >
210
+ will contain the same number of L < Pair > s as items in the C < .value > , with each
211
+ of those items a C < .key > of a pair and the C < .key > of the invocant the C < .value >
212
+ of that pair:
215
213
216
- my Pair $p3 = ('Perl' => { cool => 'language'});
217
- say $p3.invert; # OUTPUT: «{cool => language => Perl}»
218
- say $p3.invert.WHAT; # OUTPUT: «(Hash)»
214
+ :foo<Perl is great>.invert.perl.say;
215
+ # OUTPUT: «(:Perl("foo"), :is("foo"), :great("foo")).Seq»
216
+
217
+ :foo{ :42a, :72b }.invert.perl.say;
218
+ # OUTPUT: «((:a(42)) => "foo", (:b(72)) => "foo").Seq»
219
219
220
220
= head2 method keys
221
221
0 commit comments