otp
otp copied to clipboard
Add support to in place add/remove key/values of map in ets:select_replace with match spec
Is your feature request related to a problem? Please describe.
ets:select_replace/2 can use match spec to do in place replacement with List, which is efficient. But it doesn’t support updating map in place.
For example, the change to a list works:
ets:fun2ms(fun({K, L}) when is_list(L) → {K, [marker | L]} end).
Output:
[{{‘$1’,‘$2’},[{is_list,‘$2’}],[{{‘$1’,[marker|‘$2’]}}]}]
But for something similar with map:
ets:fun2ms(fun({K, Map}) when is_map(Map) → {K, Map#{marker => true}} end).
Output:
Error: the language element map (in body) cannot be translated into match_spec {error,transform_error}
Is Erlang/OTP team considering adding support to map as well?
Describe the solution you'd like
ets:select_replace/2 can use match spec to efficiently in place add/remove key/values from a map.
Describe alternatives you've considered
Right now in order to update a map, it needs to read from ets, make the changes, then copy the new map back to ets, which is very inefficient for bigger map. Since Erlang/OTP already support select by key with match spec, it would be consistent to support modification as well.
Additional context