Documentation for routine kv

Documentation for routine kv, assembled from the following types:

language documentation Typesystem

From Typesystem

(Typesystem) method kv

Defined as:

multi method kv(::?CLASS:D:)

Returns a list with key and value of the enum-pair.

say g.kv# OUTPUT: «(g 1)␤» 

class Any

From Any

(Any) method kv

Defined As:

method kv(--> List)

Returns an empty List.

say Any.kv# OUTPUT: «()␤» 

class List

From List

(List) routine kv

Defined as:

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

Returns an interleaved sequence of indexes and values. For example

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

role Baggy

From Baggy

(Baggy) method kv

Defined as:

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

Returns a Seq of keys and values interleaved.

my $breakfast = bag <eggs spam spam spam>;
say $breakfast.kv;                                # OUTPUT: «(spam 3 eggs 1)␤» 
 
my $n = ("a" => 5"b" => 2"a" => 1).BagHash;
say $n.kv;                                        # OUTPUT: «(a 6 b 2)␤» 

class Capture

From Capture

(Capture) method kv

Defined as:

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

Returns a Seq of alternating keys and values. The positional keys and values, if any, comes first followed by the named keys and values.

my $capture = \(23apples => (red => 2));
say $capture.kv;                                  # OUTPUT: «(0 2 1 3 apples red => 2)␤» 

class Map

From Map

(Map) method kv

Defined as:

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

Returns a Seq of keys and values interleaved.

Map.new('a'1'b'2).kv  # (a 1 b 2) 

class Pair

From Pair

(Pair) method kv

Defined as:

multi method kv(Pair:D: --> List:D)

Returns a two-element List with the key and value parts of Pair, in that order. This method is a special case of the same-named method on Hash, which returns all its entries as a list of keys and values.

my $p = (Perl => 6);
say $p.kv[0]; # OUTPUT: «Perl␤» 
say $p.kv[1]; # OUTPUT: «6␤» 

role Setty

From Setty

(Setty) method kv

Defined as:

multi method kv(Setty:D: --> Seq:D)

Returns a Seq of the set's elements and True values interleaved.

my $s = Set.new(123);
say $s.kv;                                        # OUTPUT: «(3 True 1 True 2 True)␤»