Documentation for routine pairs
assembled from the following pages:
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: 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.
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.
say <a b c>.pairs; # OUTPUT: «(0 => a 1 => b 2 => c)»
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)»
Class: Pair §
From Pair
(Pair) method pairs §
Defined as:
multi method pairs(Pair:)
Returns a list of one Pair
, namely this one.
my = (Raku => "d");say .pairs.^name; # OUTPUT: «List» say .pairs[0]; # OUTPUT: «Raku => d»
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)»