my %f;
for $*HOME.dir() -> $file {
my $filename = $file.basename;
%f{$filename}.push: $file, rand;
}
my $p = %f.pick; # just need any old random element
say $p.^name;
say "{$p.values.^name} has {$p.values.elems} elements";
say "{$p.values[0].^name} has {$p.values[0].elems} elements";
say '';
say $*RAKU;
say $*DISTRO;
say $*KERNEL;
say $*VM;
Output:
Pair
Seq has 1 elements
Array has 2 elements
Raku (6.d)
macos (13.2.1)
darwin
moar (2023.02)
Why is the .values of $p a Seq of Array, rather than a simple Array?
As your say $p.^name line shows, $p is a Pair. The value of this Pair is an Array; and if you called $p.value, you'd get that Array. But $p.values (with an "s") returns a sequence of all of $p's values – that is,Seq containing one Array.
Why is the .values of %f a Seq of Array
(I'm not sure this was a typo, but note that you called .values on the .first element of %f, not on %f itself. Calling .values on all of %f would also give you a Seq of Arrays, but with more elements (one for each entry in %f. Also note that %f (a Hash) isn't ordered, and thus .first doesn't return a consistent element – which is very rarely what you want.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With