routine kv
1 | class List |
1.1 | (List) routine kv |
2 | class Capture |
2.1 | (Capture) method kv |
3 | class Any |
3.1 | (Any) method kv |
4 | role Baggy |
4.1 | (Baggy) method kv |
5 | role Setty |
5.1 | (Setty) method kv |
6 | role Enumeration |
6.1 | (Enumeration) method kv |
7 | class Pair |
7.1 | (Pair) method kv |
8 | class Map |
8.1 | (Map) method kv |
Documentation for routine kv
assembled from the following types:
class List
From List
(List) routine kv
Defined as:
sub kv( --> Seq)method kv(List: --> Seq)
Returns an interleaved sequence of indexes and values. For example
<a b c>.kv; # (0 a 1 b 2 c)
class Capture
From Capture
(Capture) method kv
Defined as:
multi method kv(Capture: --> Seq)
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 = \(2, 3, apples => (red => 2));say .kv; # OUTPUT: «(0 2 1 3 apples red => 2)»
class Any
From Any
(Any) method kv
Defined as:
multi method kv(Any:)multi method kv(Any:)multi sub kv()
Returns an empty List if the invocant is a type object:
Sub.kv.say ;# OUTPUT: «()»
It calls list
on the invocant for value objects and returns the result of List.kv on it as a list where keys and values will be ordered and contiguous
<1 2 3>.kv.say; # OUTPUT: «(0 1 1 2 2 3)»
In the case of Positional
s, the indices will be considered keys.
role Baggy
From Baggy
(Baggy) method kv
Defined as:
method kv(Baggy: --> Seq)
Returns a Seq
of keys and values interleaved.
my = bag <eggs spam spam spam>;say .kv; # OUTPUT: «(spam 3 eggs 1)»my = ("a" => 5, "b" => 2, "a" => 1).BagHash;say .kv; # OUTPUT: «(a 6 b 2)»
role Setty
From Setty
(Setty) method kv
Defined as:
multi method kv(Setty: --> Seq)
Returns a Seq of the set's elements and True
values interleaved.
my = Set.new(1, 2, 3);say .kv; # OUTPUT: «(3 True 1 True 2 True)»
role Enumeration
From Enumeration
(Enumeration) method kv
Defined as:
multi method kv(::?CLASS:)
Returns a list with key and value of the enum-pair.
say g.kv; # OUTPUT: «(g 1)»
class Pair
From Pair
(Pair) method kv
Defined as:
multi method kv(Pair: --> List)
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 = (Perl => 6);say .kv[0]; # OUTPUT: «Perl»say .kv[1]; # OUTPUT: «6»
class Map
From Map
(Map) method kv
Defined as:
method kv(Map: --> Seq)
Returns a Seq
of keys and values interleaved.
Map.new('a', 1, 'b', 2).kv # (a 1 b 2)