In Pair§

See primary documentation in context for method pairs

multi method pairs(Pair:D:)

Returns a list of one Pair, namely this one.

my $p = (Raku => "d");
say $p.pairs.^name# OUTPUT: «List␤» 
say $p.pairs[0];    # OUTPUT: «Raku => d␤»

In Capture§

See primary documentation in context for method pairs

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

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 $c = \(23apples => (red => 2));
say $c.pairs# OUTPUT: «(0 => 2 1 => 3 apples => red => 2)␤»

In Any§

See primary documentation in context for method pairs

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

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 role Baggy§

See primary documentation in context for method pairs

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

Returns all elements and their respective weights as a Seq of Pairs where the key is the element itself and the value is the weight of that element.

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

In Map§

See primary documentation in context for method pairs

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

Returns a Seq of all pairs in the Map.

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

In List§

See primary documentation in context for routine pairs

sub    pairs($list --> Seq:D)
method pairs(List:D: --> Seq:D)

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)␤»