> Sent: Wednesday, September 13, 2017 at 11:23 AM
> From: "Edward Minnix" <egregius...@gmail.com>
> To: "Jason H" <jh...@gmx.com>
> Cc: Python-Ideas <python-ideas@python.org>
> Subject: Re: [Python-ideas] Make map() better
>
> While I agree that the method calling syntax is nicer, I disagree with 
> flipping the argument error for three main reasons.
> 
> First: it violates the signature entirely
> The signature to map is map(function, *iterables). Python’s map is more like 
> Haskell’s zipWith. Making the function last would either ruin the signature 
> or would slow down performance.
> 
> Second: currying
> If you ever curry a function in Python using functools.partial, having the 
> most common arguments first is crucial. (You’re more likely to apply the same 
> function to multiple iterables than to apply several functions on the same 
> exact iterable).
> 
> Thirdly: the change would make several functional programming packages have 
> incompatible APIs.
> Currently libraries like PyToolz/Cytoolz and funcy have APIs that require 
> function-first argument order. Changing the argument order would be 
> disruptive to most Python FP packages/frameworks.
> 
> So while I agree with you that “iterable.map(fn)” is more readable, I think 
> changing the argument order would be too much of a breaking change, and there 
> is no practical way to add “iterable.map(fn)” to every iterable type.


Thanks for the insights.
I don't think it would be that breaking:

def remap_map(a1, a2):
  if hasattr(a1, '__call__'):
    return map(a1, a2)
  elif hasattr(a2, '__call__'):
    return map(a2,a1)
  else:
    raise NotCallable # Exception neither is callable
    

I'm rather surprised that there isn't a Iterable class which dict and list 
derive from.
If that were added to just dict and list, I think it would cover 98% of cases, 
and adding Iterable would be reasonable in the remaining scenarios.


_______________________________________________
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to