Basics
This check is disabled by default.
Learn how to enable it via .credo.exs.
This check has a base priority of normal and works with any version of Elixir.
Explanation
Enum.flat_map(list, fn x -> if cond, do: [x], else: [] end) is just
Enum.filter/2 with extra steps.
# bad — flat_map wrapping filter logic in singleton/empty lists
Enum.flat_map(items, fn item ->
if item.active, do: [item], else: []
end)
# good — use Enum.filter
Enum.filter(items, & &1.active)Check-Specific Parameters
There are no specific parameters for this check.
General Parameters
Like with all checks, general params can be applied.
Parameters can be configured via the .credo.exs config file.