[Python-ideas] Rehabilating reduce (as "fold")

Mathias Panzenböck grosser.meister.morti at gmx.net
Fri Jul 12 16:37:57 CEST 2013


On 07/12/2013 04:17 PM, Joshua Landau wrote:
> On 12 July 2013 14:50, Mathias Panzenböck <grosser.meister.morti at gmx.net> wrote:
>> On 07/12/2013 08:01 AM, Nick Coghlan wrote:
>>>
>>>
>>> I'd personally be in favour of the notion of also allowing strings as the
>>> first argument, so you could instead write:
>>>
>>>       data = fold("+=", [], iterables)
>>>
>>>
>>
>> I'd like to see a more Haskell like way to reference operators:
>>
>>          data = fold((+=), [], iterables)
>>
>> (+=) would just be a short syntax for operator.iadd without the need to
>> explicitly import any module. It should
>> generate the same byte code.
>>
>> But I have the feeling that won't happen. :/
>
> Damn straight! Do you realise how much of an attractive nuisance that
> would be for people constantly begging "I have (+) now so why do I
> have to write lambda for <blah blah blah>" and then Guido gets upset
> because he's covered this so many times before and no-one will just
> agree goddamnit?
>

I get your point, but (+) wouldn't be a lambda. It would just be a shorthand
for operator.add. So you could write (+)(a, b) instead of a + b. Well, thinking
of that maybe it's not such a good idea.


More information about the Python-ideas mailing list