Hacker News new | past | comments | ask | show | jobs | submit login

Yes, lots of them are available. But I also would like to be able to call .sum() on my iterable at the end of a chain, instead of having to mentally unwrap sum(map(filter(filter(map(...))))



I bet a Clojure-style ‘threading’ arrow function can be easily done in Python.

  arrow(my_list [map args] [filter args] [filter args] [map args] [sum])
For cases when function argument positions differ, you'll need some special var in your module to signal where to inject the list.

  arrow(my_list [map map_func arrow.list_here])
Won't be surprised if something like this already exists, but I can't think of keywords to search for that aren't too generic.


> But I also would like to be able to call .sum() on my iterable at the end of a chain

Yeah, one thing I like about Ruby over Python is the fluent code th former allows of that style.

People talk about Guido not liking functional style, but that explains comprehensions over map/filter, but not function-sum() over method .sum().


But you only ever need to unwrap one sum(). And with sequence comprehensions, what you get instead is sum(... for ... if ... for ... if ...) - I don't think that's improved by rewriting it as (...).sum().


There's a not unreasonable position implicit in Python's way that the "most significant" operation should be most visible.

The problem with filter chaining is the final assignment and the actual value are separated by the rest of the chain.

i.e. x = strList.filter(parseInt).sum() doesn't tell me what type x is till I read the whole line.

Whereas:

x = sum( parseInt(v) for v in strList ) tells me as quickly as possible that I'm dealing with a single value output that will be a sum.


I strongly dislike python, I often wonder if it would have been as popular if Guido didn't work at Google early on.


Guido joined Google in 2005, and it was already plenty popular by then.


FWIW Python was fourteen years old when GVR joined the Borg. That doesn't address how popular it was but I think it's reasonable to say it was well established.


Why do you strongly dislike Python? Language design, standard library, community, leadership?


Mostly language design.

Guido van Rossum doesn't appreciate FP and he really genuinely doesn't understand it. That's not to say he's dumb or not a nice guy or anything. It's just not his area. And this is reflected in the language.

His attitude of you have to be "really smart" to understand FP is a mistake.

https://developers.slashdot.org/story/13/08/25/2115204/inter...

https://blog.finxter.com/about-guidos-fate-of-reduce-in-pyth...




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: