Param Pattern-Matching

View Source
Function argument capture pattern-matching should be consistently defined in the code.
Avoid
This is a convention aimed at ensuring consistency, rather than a coding issue.
Depending on your choice, you should avoid:
% the default "avoid".
myfunc(Params = #{pattern := ToMatch})or:
myfunc(#{pattern := ToMatch} = Params).Prefer
Depending on your choice, you should prefer:
% the default "prefer".
myfunc(#{pattern := ToMatch} = Params)or:
myfunc(Params = #{pattern := ToMatch}).Rationale
When capturing arguments through pattern matching in function clauses, itβs important to maintain consistency across the codebase. Capturing function arguments with different styles (e.g., placing the variable on the left or right side of the pattern) can lead to confusion and make the code harder to read. Consistency in style improves maintainability, reduces the likelihood of errors, and makes the code easier to understand for all developers. This rule ensures that the style of pattern matching for function arguments is uniform throughout the codebase.
Options
side :: left | right- default:
right
- default:
Example configuration
{elvis_style, param_pattern_matching, #{side => right}}