W0030 - Maps Put Function Rather Than Syntax
Warning
main(K, V, Map) ->
maps:put(K, V, Map).
%% ^^^^^^^^^^^^^^^^^^^💡 information: Consider using map syntax rather than a function call.
Explanation
The warning message indicates that a key-value is being inserted into a map
using the maps:put/3
function call rather than the dedicated syntax.
Whilst this will correctly and unconditionally insert 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:put/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, for performance and code clarity, if
the key should already exist in the Map
.