[Python-ideas] Another attempt at a sum() alternative: the concatenation protocol

Terry Reedy tjreedy at udel.edu
Tue Jul 23 18:33:48 CEST 2013


On 7/23/2013 3:24 AM, Andrew Barnert wrote:

> Remember that the whole point of the iteration protocols is that you
> generally don't care what type you're iterating over. And when you do
> care, you usually want to build a collection of some specific type
> out of an iterable, again without caring about the original type. You
> want a list, or a blist.sortedlist, or whatever, and it doesn't
> matter that what was passed in was a list, a tuple, or something
> else.

Right. Chaining interators is the iterator equivalent of summing lists 
or tuples or and homogeneous collections of some specific concrete 
collection type. If we were designing sum() today, I think we would 
either restrict input to numbers *or* divide inputs into numbers and 
iterables and chain the latter. However, returning either a number or 
iterator seems awkward, so two functions is probably better. I am 
warning to the idea of making chain a builtin and possible deprecating 
non-number imputs to sum.

-- 
Terry Jan Reedy



More information about the Python-ideas mailing list