On Fri, 12 Jul 2013 16:01:07 +1000 Nick Coghlan firstname.lastname@example.org wrote:
The strange contortions of the "fast sum for lists" discussions got me wondering about whether it was possible to rehabilitate reduce with a less error-prone API. It was banished to functools in 3.0 because it was so frequently used incorrectly, but now its disfavour seems to be causing people to propose ridiculous things.
I would disagree with this interpretation. reduce() wasn't "banished" (what a strange qualification!) because its API was "error-prone", but because the whole concept isn't very useful - and, indeed, little used - in a language like Python.
So, what if we instead added a new alternative API based on Haskell's "fold"  where the initial value is mandatory:
def fold(op, start, iterable): ...
So fold(op, start, iterable) is the same as reduce(op, iterable, start)? This sounds silly and useless.