Forbid map/filter with lambda
See original GitHub issueRule request
Thesis
Forbid using lambda
inside of map
and filter
.
# bad
map(lambda x: x*2, lst)
# good
(x*2 for x in lst)
# bad
filter(lambda x: x%2, lst)
# good
(x for x in lst if x%2)
# using functions instead of lambdas is ok
map(str, lst)
str(str.islower, lst)
Reasoning
Generator expressions are good, easier to read, faster, and even shorter.
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:10 (7 by maintainers)
Top Results From Across the Web
Lambda Functions in Python — Filter, Map & Reduce
A lambda function is an anonymous function with syntax lambda args: expression . The expression is executed on the arguments and the result...
Read more >Lambda event filtering - AWS Documentation
Use event filtering with a Lambda event source mapping to filter out stream and queue events to your Lambda function based on certain...
Read more >Functions in Python along with Map, Filter, and Lambda ...
A filter is a function that can be applied to a list that will return only the values that pass a certain condition....
Read more >4. Lambda Operator, filter, reduce and map - Python Courses eu
The lambda operator or lambda function is a way to create small anonymous functions, i.e. functions without a name. These functions are throw- ......
Read more >List comprehension vs. lambda + filter - python - Stack Overflow
The first is the function call overhead: as soon as you use a Python function (whether created by def or lambda ) it...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I totally agree with this statement. There are cases in which using lambdas makes your code cleaner, more readable, and even faster. There are also cases in which using them transforms you code into a mess of complicated functional nonsense. Finding a balance between lambdas, generators, and functions, is a must to write good code, but simply forbidding their usage will not necessarily improve someone’s code.
In my humble opinion, the usage of lambdas depends on the context and complexity of the code and thus forbidding it might be too strict for a big amount of developers.
@AlwxSin consider using real monads instead! (just joking 🙂 )