I published a rule that can be used to enforce varying levels of function simplification
elm-review-reducible-lambdas. The default settings are probably a little more aggressive than most in the community would prefer. However, you may be able to tinker with the settings to find a useful sweet spot for your project and so I decided to share in case anyone finds this useful.
Conservative Settings
This example config will only reduce single argument lambdas that have single letter argument names (thanks to @Arkham for the argument name predicate suggestion).
Error
-
\a -> someFunction a
will reduce tosomeFunction
Not Error
-
\apples -> someFunction apples
due to argument name length -
\a b -> someFunction a b
due to multiple arguments.
config : List Rule
config =
[ NoEtaReducibleLambdas.rule
{ lambdaReduceStrategy = NoEtaReducibleLambdas.OnlyWhenSingleArgument
, argumentNamePredicate = \argumentName -> String.length argumentName == 1
}
]
More Aggressive
These are the default settings. These may reduce a little too aggressively for most.
Error
-
\apples -> someFunction apples
reduces tosomeFunction
-
\apples bananas -> someFunction apples bananas
reduces tosomeFunction
-
\apples bananas -> someFunction milk apples bananas
reduces tosomeFunction milk
-
\apples bananas -> fn (apples 15) bananas
reduces to\apples -> fn (apples 15)
Not Error
-
\bananas -> fn (apples 15) bananas
because removing the lambda would change performance attributes by immediately evaluating(apples 15)
.
config : List Rule
config =
[ NoEtaReducibleLambdas.rule
{ lambdaReduceStrategy = NoEtaReducibleLambdas.RemoveLambdaWhenNoCallsInApplication
, argumentNamePredicate = always True
}
]