Credence.Pattern.PreferConcatOverFlatMapIdentity
(credence v0.8.0)
Copy Markdown
Detects Enum.flat_map(enumerable, fn x -> x end) which is an identity
flat-map and can be simplified to Enum.concat(enumerable).
LLMs sometimes generate Enum.flat_map(fn x -> x end) instead of the
simpler Enum.concat/1. This pattern also appears in piped form.
Bad
matrix |> Enum.flat_map(fn row -> row end)
Enum.flat_map(list_of_lists, fn x -> x end)Good
Enum.concat(matrix)
Enum.concat(list_of_lists)