In role Baggy§
See primary documentation in context for method pairs
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)»
In Capture§
See primary documentation in context for method pairs
multi method pairs(Capture: --> Seq)
Returns all arguments, the positional followed by the named, as a Seq
of Pair
s. 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)»
In Any§
See primary documentation in context for method pairs
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.
In Map§
See primary documentation in context for method pairs
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)»
In Pair§
See primary documentation in context for method pairs
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»
In List§
See primary documentation in context for routine pairs
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)»