3 ms·
> perpetuates the idea that Python won't let you write elegant and stateless programs that behave in a functional manner Well, in my opinion Python really does
by bad_user 9y ago
> perpetuates the idea that Python won't let you write elegant and stateless programs that behave in a functional manner
Well, in my opinion Python really does not let you write elegant and stateless programs that behave in an FP manner.
The sample you've chosen in particular is all fine, except that `lambda` expressions are almost never used, due to Python not being expression oriented, so there isn't much you can express with a `lambda`.
You might find your `for x in seq if even(x)` expression elegant, but it is preceded by a `return`. Python is a statement / side effects oriented language and even in your one liner, it shows.
Oh, and given that a Python "generator" is like Java's Iterable / Iterator, that's not FP either, although you can argue that the mutation can be localized (e.g. in your `sum` example), but you have to be careful about it.
And if you'll take a look at the whole Python ecosystem, there's not much FP in it to be honest. I mean, seriously, out of all the mainstream languages, I can't think of a worse language to do FP than Python, except for C maybe,
- merlincorey 9y agoCheck out toolz[0] for a Clojure inspired FP toolkit in Python. [0] http://toolz.readthedocs.io/en/latest/ http://toolz.readthedocs.io/en/latest/