THIS Will Give Python Devs A Heart Attack

preview_player
Показать описание
This will give Python devs a heart attack. #Python #Code #Shorts
Рекомендации по теме
Комментарии
Автор

This is function currying, it is not crazy at all, in fact it is basic functional programming

ivandiazalvarez
Автор

This is the Currying concept/technique and is also in Javascript and pure functional languages. The only use I've found for it is when you have a function that you don't readily have all of its parameters yet. So now I know a, but I need to get b from some async call or something. In that case I call the first partial and provide it with a, this saves a in the context and also protects it by hiding it. Later on I call the returned function and give it b to get final result from a & b.
In JS I've seen it being used and honestly after reading the so-called advantages of using it, I still wasn't convinced that they're real advantages. I believe same applies to Python. In pure (100%) functional languages like Haskell it might make more sense.

Shennzo
Автор

I actually saw this exact pattern today, used to create a decorator. The outer lambda is the decorator, which needs to take a function f, and the inner lambda is the "replacement" or "wrapper" function: it calls f and does some additional work. It's confusing if you haven't seen this pattern before, but it was a one-line definition compared to about 10 lines for a standard nested function definition. I'm not sure how common it is in production code, though (this was just an exercise).

bthrkay
Автор

or you could just give lambda 2 elements to start with:
x=lambda a, b: print(a b)
x('a', 'b')
However it is recommended to do named functions you reuse with the *def* key word.

oida
Автор

Well this is the basics of Decorators,
The ability to return functions to construct "Higher" functions.
In a function oriented programming languages like Haskell it's a very basic concept and part of the language itself.

Lambdas in Python are pretty weak - I prefer writing definitions since lambda syntax is not convenient.

TNothingFree
Автор

I thought the point of lambda was to run anonymous functions for speed.

This is just syntax gymnastics

alext
Автор

Im not developer but i have some knowledge about lamda expression

SohailAhmad-xktx
Автор

Me as a js developer: obvious stuff 🤣🤣

sidheshwartiwari
Автор

can it give me a heart attack?(i want to die)

pinklemonade