Credence.Rule.NoAnonFnApplicationInPipe (credence v0.3.1)

Copy Markdown

Readability rule: Detects anonymous functions applied with .() inside a pipeline.

Applying an anonymous function directly in a pipe (e.g. |> (fn x -> ... end).()) is non-idiomatic and hard to read. Use then/2 instead, which was added in Elixir 1.12 specifically for this purpose.

Bad

list
|> Enum.sort()
|> (fn s -> [1 | s] end).()

Good

list
|> Enum.sort()
|> then(fn s -> [1 | s] end)

# Or with capture syntax:
|> then(&[1 | &1])