Documentation for method invert, assembled from the following types:
method invert(--> List)
Returns an empty List.
say Any.invert; # OUTPUT: «()␤»
method invert(Baggy: --> Seq)
Returns all elements and their respective weights as a Seq of Pairs, where the element itself is the value and the weight of that element is the key, i.e. the opposite of method pairs. Except for some esoteric cases
invert on a Baggy type returns the same result as antipairs.
my = bag <bacon eggs bacon>;my = .invert;say .sort; # OUTPUT: «(1 => eggs 2 => bacon)␤»
method invert(Map: --> Seq)
Returns all keys and their respective values as a Seq of
Pairs where the keys and values have been exchanged. The difference between
invert and antipairs is that
invert expands list values into multiple pairs.
my = Map.new('a' => (2, 3), 'b' => 17);say .invert; # OUTPUT: «(2 => a 3 => a 17 => b)␤»
method invert(Pair: --> Seq)
:foo<bar>.invert.perl.say; # OUTPUT: «(:bar("foo"),).Seq»
.value is an Iterable, the returned Seq will contain the same number of Pairs as items in the
.value, with each of those items a
.key of a pair and the
.key of the invocant the
.value of that pair:
:foo<Perl is great>.invert.perl.say;# OUTPUT: «(:Perl("foo"), :is("foo"), :great("foo")).Seq»:foo.invert.perl.say;# OUTPUT: «((:a(42)) => "foo", (:b(72)) => "foo").Seq»
To perform the exact
.value swap, use