Skip to content

Commit edd7431

Browse files
committed
Fix up Pair.invert docs
- It (since a few months ago) always returns a Seq; old behaviour was not specced. - Simply examples Spec: Raku/roast@f4828aaf64 Fixes RT#131349: https://rt.perl.org/Ticket/Display.html?id=131349
1 parent 2cff5dd commit edd7431

File tree

1 file changed

+15
-15
lines changed

1 file changed

+15
-15
lines changed

doc/Type/Pair.pod6

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -197,25 +197,25 @@ of the invocant.
197197
198198
Defined as:
199199
200-
method invert(Pair:D:)
200+
method invert(Pair:D: --> Seq:D)
201201
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:
207206
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»
211208
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:
215213
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»
219219
220220
=head2 method keys
221221

0 commit comments

Comments
 (0)