Credence.Rule.NoMapKeysOrValuesForIteration
(credence v0.2.0)
Copy Markdown
Performance rule: Detects Map.values(map) or Map.keys(map) passed
directly into an Enum function, which creates an unnecessary intermediate
list.
All Enum functions accept maps directly and iterate over {key, value}
pairs without allocating an intermediate list.
Bad
Enum.all?(Map.values(degrees), fn v -> v == 0 end)
Map.keys(map) |> Enum.map(&to_string/1)Good
Enum.all?(degrees, fn {_k, v} -> v == 0 end)
Enum.map(map, fn {k, _v} -> to_string(k) end)