How do use a sort on a hash in a for
The neater way:
for %h.sort -> (:key($name), :value($num)) {
This destructures the Pair
by calling .key
and .value
on it, and then binding them to $name
and $num
respectively.
Perhaps a shorter, more understandable version:
for %h.sort -> (:$key, :$value) {
which would create variables with the same names the methods got called with.