[Python-ideas] Reduce/fold and scan with generator expressions and comprehensions
Danilo J. S. Bellini
danilo.bellini at gmail.com
Sun Oct 23 11:28:51 EDT 2016
>
> What is `last(inf_iter)`. E.g `last(count())`.
The "last" is just a helper function that gets the last value of an
iterable. On sequences, it can be written to get the item at index -1 to
avoid traversing it. Using it on endless iterables makes no sense.
This makes it clear that is the users job to make sure `it` terminates.
If one call "last" for something that doesn't terminate, an "endless"
iterable, well, it's pretty obvious that it won't "end" nicely. It's not
the Python job to solve the Entscheidungsproblem. If you call "sorted" on
endless iterables, it would behave like "last", doesn't it?
The whole point of this idea is the scan as a generator expression or
list/set comprehension that can access the previous iteration output.
Reduce/fold is just the last value of a scan, and the scan is still defined
when there's no "last value".
--
Danilo J. S. Bellini
---------------
"*It is not our business to set up prohibitions, but to arrive at
conventions.*" (R. Carnap)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20161023/f7ca4164/attachment.html>
More information about the Python-ideas
mailing list