I'm trying to use the any
or none
on the keys or values of a hash like that:
my %w=(a => 1, b => 2);
say %w.keys; # works
say so 'a' == %w.keys.any; # doesn't work
I've checked the Raku documentation's hash and map section but couldn't fix this issue. How to fix it? Thanks.
The code dies like this:
Cannot convert string to number: base-10 number must begin with
valid digits or '.' in '⏏a' (indicated by ⏏)
This happens because ==
is the numeric comparison operator, so it first tries to coerce the arguments into a number before doing the comparison.
Hash keys - at least by default - are strings, thus the eq
operator for string comparison is needed here:
my %w=(a => 1, b => 2);
say so 'a' eq %w.keys.any; # True
use cmp
operator when compares with string:
say so 'a' cmp %w.keys.any;
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