News for hackers. Stuff that matters.
Re:Functools – The Power of Higher-Order Functions in Python by patterns on Friday July 09, 2021 @08:40AM (#27783082)
I agree.

One gripe that I have with functions like map is that it returns a generator, so you have to be careful when reusing results. I fell into this trap a few times.

I'd also like a simpler syntax for closures, it would make writing embedded DSLs less cumbersome.

Re:Functools – The Power of Higher-Order Functions in Python by zbentley on Friday July 09, 2021 @08:59AM (#27783231)
> One gripe that I have with functions like map is that it returns a generator, so you have to be careful when reusing results

I hope that is never changed; I often write code in which the map function's results are very large, and keeping those around by default would cause serious memory consumption even when I am mapping over a sequence (rather than another generator).

Instead, I'd advocate the opposite extreme: Python makes it a little too easy to make sequences/vectors (with comprehensions); I wish generators were the default in more cases, and that it was harder to accidentally reify things into a list/tuple/whatever.

I think that if the only comprehension syntax available was the one that created a generator--"(_ for _ in _)"--and you always had to explicitly reify it by calling list(genexp) or tuple(genexp) if you wanted a sequence, then the conventions in the Python ecosystem would be much more laziness-oriented and more predictable memory-consumption wise.

Ah well, water under the bridge, I know.

Re:Functools – The Power of Higher-Order Functions in Python by EE84M3i on Friday July 09, 2021 @09:11AM (#27783310)
Personally, I mostly just avoid using map/filter and use a list/generator/set/dict comprehension as required. I don't find map(foo, bar) much easier to read than [foo(thingamajig) for thingamajig in bar]
Re:Functools – The Power of Higher-Order Functions in Python by robertlagrant on Friday July 09, 2021 @10:35AM (#27784076)
Yes, this is I think why Guido wanted to get rid of map() syntax - he prefers comprehension syntax.
Re:Functools – The Power of Higher-Order Functions in Python by ehsankia on Friday July 09, 2021 @10:57AM (#27784344)
Simply wrap it in list(), or use a list comprehension. Most things in python3 are iterators now, so the same thing applies to many things.
Re:Functools – The Power of Higher-Order Functions in Python by pantsforbirds on Friday July 09, 2021 @11:03AM (#27784398)
i think thats the most powerful part of the tool. being able to effortlessly write lazy generators is absolutely amazing when working with any sort of I/O system or async code.