I'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`.
Re:Functional Programming in Python [pdf]
by gamegoblin on Saturday July 25, 2015 @01:31AM
(#9946670)
The ugly hack around this would be
lambda x: (lambda y: f(y) + g(y))(expensive_computation(x))
Re:Functional Programming in Python [pdf]
by gamegoblin on Saturday July 25, 2015 @01:29AM
(#9946663)
It's possible to hack currying into python with a decorator like:
https://gist.github.com/grantslatton/9221084
(I made this for fun, use at your own risk)
It's also worth noting that reduce() was removed as a builtin for Python 3.