2 ms·
Your example translated to Python is also lazily generated (it uses the lazy equivalent of list comprehensions, called generator expressions): source = count
by icebraining 10y ago
Your example translated to Python is also lazily generated (it uses the lazy equivalent of list comprehensions, called generator expressions):
source = count(1)
elevensies = (x * 11 for x in source)
odd_elevensies = (x for x in elevensies if x%2)
root_of_odd_elevensies = (math.sqrt(x) for x in odd_elevensies)
To me, the examples seem fairly equivalent, with the exception that Python's is, in my opinion, more readable for a newbie, since it doesn't require knowing map() or grep() - just for loops and ifs.
- kbenson 10y agoI was aware of generators in python, but I wasn't aware of the lazy lest comprehensions, which is very nice. I agree list comprehensions in the simple form are easier for a newbie to recognize, but I also like the way map and filter make you think about your actions, and think they are clearer in the less trivial cases (as I mentioned above). I say "filter" because while I am completely familiar with that terminology, I accept that it's an unneeded departure from the common terminology for that task.
- icebraining 10y agoWell, map and filter may be more clear in certain cases, but I still don't see how they are more powerful. Seems like you can do a 1-for-1 translation between the two.
- kbenson 10y agoOh, that's because you must have missed a few comments back where I agreed with you and backed out on any claim they were strictly more powerful. ;)
- icebraining 10y agoAh, uh, sorry ;)