W0031 - Maps Update Function Rather Than Syntax
Warning
main(K, V, Map) ->
maps:update(K, V, Map).
%% ^^^^^^^^^^^^^^^^^^^^^^💡 information: Consider using map syntax rather than a function call.
Explanation
The warning message indicates that a key-value is being updated in a map
using the maps:update/3
function call rather than the dedicated syntax.
Whilst this will correctly update the key-value into the map, it is not considered idiomatic, and may be less efficient than using the map update syntax directly.
If the keys are constants known at compile-time, using the map update syntax
with the :=
operator is more efficient than multiple calls to maps:update/3
,
especially for small maps. This implies than using the :=
operator should
making future additions to the code also both performant and clear.
To fix the issue, use the built-in Map#{Key := Value}
syntax to insert the
Key
and Value
into the Map
:
main(K, V, Map) ->
Map#{K := V}.
Note: Use the =>
operator instead, if the key may not already exist in
the Map
.