How about writting modern and proper Python first? Not to mention designing a decent API? Let's examine the README example for a minute: user: Optional[User] if user is not None: balance = user.get_balance() if balance is not None: balance_credit = balance.credit_amount() if balance_credit is not None and balance_credit > 0: can_buy_stuff = True else: can_buy_stuff = False I don't know if it's been deliberatly twiste…
I'd like to know what happens to can_buy_stuff and the rest of the code when user is Not None and balance_credit is -1.
Functional Programming in Python
61–64 of 64 posts
Re: Functional Programming in Python
#62Functional programming in Python: Step 1: try to integrate more functional methods in your current Python programming due to their usefulness. Step 2: get increasingly frustrated, and then give up, because Guido and the Python devs seemingly hate functional programming and keep hobbling it.
A part of me is happy to see these types of tools introduced to python, but another part makes me wonder why people continue to use python when they see the value of things like `Option`/`Maybe`'s, `Result`'s, instead of just using a language with the features included from the start. In my experience, the initial ease and speed of development when using python doesn't nearly outweigh the medium to long-term costs of…
Mostly just to see what a language that 'feels like' Python would be like with the addition of things like proper Option/Result's and a couple of other features (stronger typing?).
Re: Functional Programming in Python
#63I would love to highlight several features of `0.14` release we are working on right now:
1. Typed `partial` and `curry` functions: https://returns.readthedocs.io/en/latest/pages/curry.html
2. `Future` and `FutureResult` containers for working with async Python! https://returns.readthedocs.io/en/latest/pages/future.html
3. Typed functional pipelines with very good type inference: https://returns.readthedocs.io/en/latest/pages/pipeline.html
It is going to be released soon, stay tuned!
Re: Functional Programming in Python
#64Earlier quoted context omitted.
lambda use in Python is discouraged in general. If you need something beyond an expression, PEP-8 encourages you to use a def in that case instead.
The issue with that is the lack of lexical scope. Lambdas have lexical scoping, def functions do not. To “fake” lexical scope, you have to use the nonlocal or global statements, which are gross and self-defeating.
x = 3
def prt():
print(x)
prt()
prints 3, as expected.It's when you assign that you need P3's global etc. annotations, and you can't assign in lambdas.