Credence.Pattern.PreferMapNew (credence v0.8.0)

Copy Markdown

Detects Enum.into(enum, %{}) and suggests Map.new(enum) instead.

Enum.into/2 with an empty map literal %{} is the generic collectable path for building maps. Map.new/1 exists specifically for this purpose, reads as intent ("build a new map from this enumerable") rather than mechanism ("push items into an empty collectable"), and is the idiomatic Elixir choice.

Bad

Enum.into(pairs, %{})

pairs |> Enum.into(%{})

Enum.zip(keys, vals) |> Enum.into(%{})

Good

Map.new(pairs)

Map.new(pairs)

Enum.zip(keys, vals) |> Map.new()