Course of Raku / Advanced / Containers / Subscript adverbs 🆕 / Exercises / Does the key exist
Solution: Does the key exist
Here is a possible solution to the task.
Code
my %h = a => 1, b => 2;
say %h<z>:exists;🦋 You can find the source code in the file check-exists.raku.
Output
FalseComments
The
:existsadverb returns whether the key is present, without fetching the value.The hash has no key
z, so it returnsFalse— and, unlike an ordinary lookup, it does not create the key as a side effect.