routine antipairs
1 | class List |
1.1 | (List) routine antipairs |
2 | class Capture |
2.1 | (Capture) method antipairs |
3 | class Any |
3.1 | (Any) method antipairs |
4 | role Baggy |
4.1 | (Baggy) method antipairs |
5 | role Setty |
5.1 | (Setty) method antipairs |
6 | class Pair |
6.1 | (Pair) method antipairs |
7 | class Map |
7.1 | (Map) method antipairs |
Documentation for routine antipairs
assembled from the following types:
class List
From List
(List) routine antipairs
Defined as:
method antipairs(List: --> Seq)
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)»
class Capture
From Capture
(Capture) method antipairs
Defined as:
multi method antipairs(Capture: --> Seq)
Returns all arguments, the positional followed by the named, as a Seq of pairs 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 = \(2, 3, apples => (red => 2));say .antipairs; # OUTPUT: «(2 => 0 3 => 1 (red => 2) => apples)»
class Any
From Any
(Any) method antipairs
Defined as:
multi method antipairs(Any:)multi method antipairs(Any:)
Returns an empty List 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.
%(s => 1, t=> 2, u => 3).antipairs.say ;# OUTPUT: «(2 => t 1 => s 3 => u)»
role Baggy
From Baggy
(Baggy) method antipairs
Defined as:
method antipairs(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.
my = bag <bacon eggs bacon>;my = .antipairs;say .sort; # OUTPUT: «(1 => eggs 2 => bacon)»
role Setty
From Setty
(Setty) method antipairs
Defined as:
multi method antipairs(Setty: --> Seq)
Returns all elements in the set and True
as a Seq of Pairs, where the element itself is the value, i.e. the opposite of method pairs
.
my = Set.new(1, 2, 3, 1);say .antipairs.sort; # OUTPUT: «(True => 1 True => 2 True => 3)»
class Pair
From Pair
(Pair) method antipairs
Defined as:
multi method antipairs(Pair:)
Returns a List containing the antipair of the invocant.
my = (6 => 'Perl').antipairs;say .^name; # OUTPUT: «List»say .first; # OUTPUT: «Perl => 6»say .first.^name; # OUTPUT: «Pair»
class Map
From Map
(Map) method antipairs
Defined as:
method antipairs(Map: --> Seq)
Returns all keys and their respective values as a Seq of Pair
s 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 = Map.new('a' => (2, 3), 'b' => 17);say .antipairs; # OUTPUT: «((2 3) => a 17 => b)»