routine pairs
1 | class List |
1.1 | (List) routine pairs |
2 | class Capture |
2.1 | (Capture) method pairs |
3 | class Any |
3.1 | (Any) method pairs |
4 | role Baggy |
4.1 | (Baggy) method pairs |
5 | class Pair |
5.1 | (Pair) method pairs |
6 | class Map |
6.1 | (Map) method pairs |
Documentation for routine pairs
assembled from the following types:
class List
From List
(List) routine pairs
Defined as:
sub pairs( --> Seq)method pairs(List: --> Seq)
Returns a sequence of pairs, with the indexes as keys and the list values as values.
<a b c>.pairs # (0 => a 1 => b 2 => c)
class Capture
From Capture
(Capture) method pairs
Defined as:
multi method pairs(Capture: --> Seq)
Returns all arguments, the positional followed by the named, as a Seq of Pairs. Positional arguments have their respective ordinal value, starting at zero, as key while the named arguments have their names as key.
my Capture = \(2, 3, apples => (red => 2));say .pairs; # OUTPUT: «(0 => 2 1 => 3 apples => red => 2)»
class Any
From Any
(Any) method pairs
Defined as:
multi method pairs(Any:)multi method pairs(Any:)
Returns an empty List if the invocant is a type object:
say Num.pairs; # OUTPUT: «()»
For a value object, it converts the invocant to a List via the list
method and returns the result of List.pairs on it.
<1 2 2 3 3 3>.Bag.pairs.say;# OUTPUT: «(1 => 1 3 => 3 2 => 2)»
In this case, every element (with weight) in a bag is converted to a pair.
role Baggy
From Baggy
(Baggy) method pairs
Defined as:
method pairs(Baggy: --> Seq)
Returns all elements and their respective weights as a Seq of Pair
s where the key is the element itself and the value is the weight of that element.
my = bag <bacon eggs bacon>;my = .pairs;say .sort; # OUTPUT: «(bacon => 2 eggs => 1)»
class Pair
From Pair
(Pair) method pairs
Defined as:
multi method pairs(Pair:)
Returns a list of one Pair
, namely this one.
my = (Perl => 6);say .pairs.^name; # OUTPUT: «List»say .pairs[0]; # OUTPUT: «Perl => 6»
class Map
From Map
(Map) method pairs
Defined as:
method pairs(Map: --> Seq)
Returns a Seq
of all pairs in the Map.
my = Map.new('a' => (2, 3), 'b' => 17);say .pairs; # OUTPUT: «(a => (2 3) b => 17)»