3 ms·
For compose to really shine, you need to be able to curry/partially apply functions. This part of things is made much more difficult than necessary because of P
by hajile 11y ago
For compose to really shine, you need to be able to curry/partially apply functions. This part of things is made much more difficult than necessary because of Python's unnecessarily neutered lambda syntax (in fact, I don't think one can claim that Python is FP friendly until this decision is corrected).
It's also worth noting that reduce() was removed as a builtin for Python 3.
- nine_k 11y agoI'd love let-like syntax in lambdas, something along the lines of lambda x: f(y) + g(y) for y = expensive_computation(x) In Python 3, `reduce` can be trivially imported from `functools`.
- gamegoblin 11y agoThe ugly hack around this would be lambda x: (lambda y: f(y) + g(y))(expensive_computation(x))
- gamegoblin 11y agoIt's possible to hack currying into python with a decorator like: https://gist.github.com/grantslatton/9221084 https://gist.github.com/grantslatton/9221084 (I made this for fun, use at your own risk)