Credence.Pattern.PreferThenOverCaptureInvocation (credence v0.8.0)

Copy Markdown

Detects immediately-invoked captures (&body).() in pipelines and rewrites them to use Kernel.then/2 (Elixir 1.12+), which is the idiomatic replacement.

LLMs often produce |> (&(&1 == String.reverse(&1))).() — a capture expression applied with .() at the end of a pipe. This is non-idiomatic; Kernel.then/2 was added in Elixir 1.12 specifically for this purpose.

Only captures that use exactly &1 (arity 1) are rewritten. Captures that use &2 or higher (arity > 1) or that don't use &1 at all (arity 0) are left alone because then/2 expects an arity-1 function and would raise a different error than the original .() call.

Bad

number
|> Integer.to_string()
|> (&(&1 == String.reverse(&1))).()

Good

number
|> Integer.to_string()
|> then(&(&1 == String.reverse(&1)))