antipairs
ErrorsCollection

antipairs

Synthesised documentation from type/Baggy type/Any type/Setty type/Map type/Capture type/Pair type/List

From type/Baggy

See Original text in context

method antipairs(Baggy:D: --> Seq:D)

Returns all elements and their respective weights as a Seq of Pair objects, where the element itself is the value and the weight of that element is the key, i.e. the opposite of method pairs.

my $breakfast = bag <bacon eggs bacon>;
my $seq = $breakfast.antipairs;
say $seq.sort;                                    # OUTPUT: «(1 => eggs 2 => bacon)␤»

From type/Any

See Original text in context

multi method antipairs(Any:U:)
multi method antipairs(Any:D:)

Returns an empty Any if the invocant is a type object

Range.antipairs.say# OUTPUT: «()␤»

If it's a value object, it returns the inverted list of pairs after converting it to a list of pairs; the values will become keys and the other way round.

%(=> 1t=> 2=> 3).antipairs.say ;# OUTPUT: «(2 => t 1 => s 3 => u)␤»

From type/Setty

See Original text in context

multi method antipairs(Setty:D: --> Seq:D)

Returns all elements in the set and True as a Seq of Pair objects, where the element itself is the value, i.e. the opposite of method pairs.

my $s = Set.new(1231);
say $s.antipairs.sort;                            # OUTPUT: «(True => 1 True => 2 True => 3)␤»

From type/Map

See Original text in context

method antipairs(Map:D: --> Seq:D)

Returns all keys and their respective values as a Seq of Pairs where the keys and values have been exchanged, i.e. the opposite of method pairs. Unlike the invert method, there is no attempt to expand list values into multiple pairs.

my $m = Map.new('a' => (23), 'b' => 17);
say $m.antipairs;                        # OUTPUT: «((2 3) => a 17 => b)␤»

From type/Capture

See Original text in context

multi method antipairs(Capture:D: --> Seq:D)

Returns all arguments, the positional followed by the named, as a Seq of Pair where the keys and values have been swapped, i.e. the value becomes the key and the key becomes the value. This behavior is the opposite of the pairs method.

my $capture = \(23apples => (red => 2));
say $capture.antipairs# OUTPUT: «(2 => 0 3 => 1 (red => 2) => apples)␤»

From type/Pair

See Original text in context

multi method antipairs(Pair:D:)

Returns a List containing the antipair of the invocant.

my $p = (=> 'Raku').antipairs;
say $p.^name;                                     # OUTPUT: «List␤» 
say $p.first;                                     # OUTPUT: «Raku => d␤» 
say $p.first.^name;                               # OUTPUT: «Pair␤»

From type/List

See Original text in context

method antipairs(List:D: --> Seq:D)

Returns a Seq of pairs, with the values as keys and the indexes as values, i.e. the direct opposite to pairs.

say <a b c>.antipairs;  # OUTPUT: «(a => 0 b => 1 c => 2)␤»