Documentation for routine pairs

Documentation for routine pairs, assembled from the following types:

class Any

From Any

(Any) method pairs

Defined As:

    method pairs(--> TODO)


class List

From List

(List) routine pairs

Defined as:

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.

<a b c>.pairs   # (0 => a 1 => b 2 => c) 

role Baggy

From Baggy

(Baggy) method pairs

Defined as:

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

class Capture

From Capture

(Capture) method pairs

Defined as:

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

class Map

From Map

(Map) method pairs

Defined as:

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

Returns a Seq of all pairs in the Map.

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

class Pair

From Pair

(Pair) method pairs

Defined as:

multi method pairs(Pair:D:)

Returns a list of one Pair, namely this one.

my $p = (Perl => 6);
say $p.pairs.WHAT# OUTPUT: «(List)␤» 
say $p.pairs[0];   # OUTPUT: «(Pair)␤»