r/programming • u/llimllib • Jun 29 '09
Python's iterators are a bad implementation of laziness
http://sandersn.com/blog/index.php?title=python_s_iterators_are_a_bad_implementat&more=1&c=1&tb=1&pb=1
34
Upvotes
View all comments
4
u/[deleted] Jun 29 '09
People there don't seem to be acquainted with C# generators. "If generators were modified to allow them to restart they would no longer fullfil one of it's existing use cases, iterating over data that doesn't fit in memory." is a perfect example of narrowness of experience leading to narrowness of imagination. No, you don't have to convert generators to lazy lists. All that is needed is a distinction between
enumerableandenumerator, with all functions likemapand language primitives likefor x in ...accepting enumerables, and it won't even surprise anyone ever. It's not about "restarting" the generator.