[quote=“heilong, post:19, topic:47020”]
So themap_get
Elixir guard is still needed when the key is a variable (from context, or an argument to the guarded function).
[/quote]
In many cases you would be either using pattern-matching directly (%{^key => value}
), have a known key map.known_key
, or if you just want to check for the key presence use is_map_key/2
.
In the rare case where you need to access a dynamic key to implement a complex guard, :erlang.map_get/2
is still an option.
If it was most commonly used, I suppose we could make a kernel function for it, but it would be redundant with Map.fetch!/2
when used outside of guards.
I found a relevant discussion here.
Relevant to this topic: Implement guard-safe `MapSet.is_member/2` by christhekeele · Pull Request #13386 · elixir-lang/elixir · GitHub.
TLDR: we could do it today, but it might prevent future changes to the internals of MapSet
that might not be guard-compatible.
The same applies to other guards and proposals I think. Sets are not a primitive type on the BEAM like lists or maps: they are implemented using maps (:sets
v2) or tuples (:gb_sets
).