Credence.Pattern.NoManualMin
(credence v0.7.0)
Copy Markdown
Detects if expressions that manually reimplement Kernel.min/2.
Why this matters
LLMs frequently expand min(a, b) into conditional form because they
translate from languages where min is less ergonomic or unavailable
as an infix/kernel function:
# Flagged — manual reimplementation
threshold = if(a < b, do: a, else: b)
# Idiomatic — Kernel.min/2
threshold = min(a, b)Kernel.min/2 is clearer, shorter, and communicates intent directly.
Flagged patterns
Only the non-strict comparison forms are flagged, because only they equal
min/2 for every input. min/2 returns its first argument on a tie, so:
| Pattern | Replacement | Flagged? |
|---|---|---|
if a <= b, do: a, else: b | min(a, b) | yes |
if b >= a, do: a, else: b | min(a, b) | yes |
if a < b, do: a, else: b | — | no |
if b > a, do: a, else: b | — | no |
The strict forms (<, >) take the else branch on a tie, which differs from
min/2 when the operands are equal in value but different in type — e.g.
min(1, 1.0) is 1, but if 1 < 1.0, do: 1, else: 1.0 yields 1.0. So they
are not rewritten.