Credence.Pattern.NoManualMin
(credence v0.6.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
Any if expression where:
- The condition is a comparison (
>,>=,<,<=), - One branch returns the left operand and the other returns the right, and
- The branch returning the "lesser" operand is the
do(true) branch.
All four comparison operators are handled:
| Pattern | Replacement |
|---|---|
if a < b, do: a, else: b | min(a, b) |
if a <= b, do: a, else: b | min(a, b) |
if b > a, do: a, else: b | min(a, b) |
if b >= a, do: a, else: b | min(a, b) |