Credence.Rule.NoListFold (credence v0.3.1)

Copy Markdown

Detects usage of List.foldl/3 and List.foldr/3 and suggests Enum.reduce/3 instead.

Why this matters

Enum.reduce/3 is the idiomatic Elixir way to fold over a collection. While List.foldl/3 and List.foldr/3 exist in Elixir's standard library, they are rarely used in practice and signal code ported from Erlang (:lists.foldl) or Haskell.

LLMs frequently generate List.foldl because their training data includes heavy Erlang and Haskell influence. The resulting code is functionally correct but non-idiomatic, which reduces readability for Elixir developers.

Flagged patterns

PatternSuggested replacement
List.foldl/3Enum.reduce/3
List.foldr/3Enum.reduce/3 (with Enum.reverse/1)