Skip to content

Instantly share code, notes, and snippets.

@dogbert17
Last active August 1, 2016 19:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dogbert17/211c376936c7c1442cdfa2a826ecc16c to your computer and use it in GitHub Desktop.
Save dogbert17/211c376936c7c1442cdfa2a826ecc16c to your computer and use it in GitHub Desktop.
Attempt to document Pair.invert
=head2 method invert
Defined as:
method invert(Pair:D:)
Usage:
PAIR.invert
Returns a new C<Pair> object with key and value exchanged, just like
L<antipair|/type/Pair#method_antipair>, unless the value of the invocant does
the L<Iterable|/type/Iterable> role. In the latter case an C<Iterable> structure
of C<Pair>s is returned since C<invert> expands iterable values into multiple
pairs.
my Pair $p1 = (6 => 'Perl');
say $p1.invert; # Perl => 6
say $p1.invert.WHAT; # (Pair)
my Pair $p2 = ('Perl' => (5, 6));
say $p2.invert; # (5 => Perl 6 => Perl)
say $p2.invert.WHAT; # (List)
my Pair $p3 = ('Perl' => { cool => 'language'});
say $p3.invert; # {cool => language => Perl}
say $p3.invert.WHAT; # (Hash)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment