You're using a "Map" when you want to use a "Bag" I think... when the Map has a count of 0, (elem) returns False.
my Map $p .= new(<d f g>.kv.reverse); # Map.new((:d(0),:f(1),:g(2))) say 'f' (elem) $p; # True say 'd' (elem) $p; # False my Bag $b .= new(<d f g>); # bag(g, f, d) say 'd' (elem) $b; # True say 'f' (elem) $b; # True say 'g' (elem) $b; # True