Skip to content

Commit d0297be

Browse files
committed
Adds example for destructuring hashes in pointy loops
Closes #1466
1 parent c91b2de commit d0297be

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

doc/Type/Signature.pod6

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -714,6 +714,14 @@ While the destructuring of a hash is its pairs:
714714
$x andthen $y andthen $z andthen True
715715
}
716716
717+
Pointy loops can also destructure hashes, allowing assignment to variables:
718+
719+
my %hhgttu = (:40life, :41universe, :42everything);
720+
for %hhgttu -> (:$key, :$value) {
721+
say "$key → $value";
722+
}
723+
# OUTPUT: «universe → 41␤life → 40␤everything → 42␤»
724+
717725
In general, an object is destructured based on its attributes. A common idiom
718726
is to unpack a L<C<Pair>>'s key and value in a for loop:
719727

0 commit comments

Comments
 (0)