Комментарии:
Lambda in JS are a lot better than in Python.
ОтветитьPython's syntax is so clean, it's beneficial to just create a function so you can actually test it. I personally avoid lambdas in python unless it's one off prototype project like cleaning data in pandas
Ответитьoh please, a lambda consists of a single expression, not a single line..
ОтветитьI like lambda functions for defining a function as a parameter to another function, so it can be passed without giving it a reference. I just think the code is a lot cleaner (unless the functions get complicated then it’s better to define the function beforehand)
ОтветитьCan’t the lambda be typed using Callable?
ОтветитьIt's undoubtedly a design flaw. Look at similar dynamic languages like Javascript and Ruby and how multiline lambdas make the code more expressive and reduce boilerplate. Hell, even Java's lambdas can be multiline.
Typing is not a problem, as demonstrated by other commenters. You would type the function receiving the lambda with Callable and let the type checker verify that the lambda satisfies the type.
Yeah, lambdas in Python are strictly worse than in Java or JavaScript.
However lack of streams and not so extensive functional approach makes poor lambdas a bit less painful.
What I would love to see in Python are Java's streams and lambdas.
For one the syntax is bit unreadable unless you use it often.
ОтветитьI'd rather say that Python doesn't really need multi line lambdas, because in Python defining function and using it as an argument looks visually and work exactly the same.
Ответитьbut is it really a flaw? I mean.. can't you simply define what you need in another function and then pass that function as a handler in a lambda? or would that defy the purpose of a lambda? Also if number of parameters would be a problem, one could use `partial` I guess... am I right? I would really like to discuss about this.. I did not see lambdas as limited up until now, but maybe I haven t used them as much as some people else
ОтветитьLambda is offended by this... She thinks that you're telling her she's flawed...
ОтветитьCheck out my channel links for a free code diagnosis workshop or my free design guide! 🔥
Ответить