[Python-ideas] Make map() better

Steven D'Aprano steve at pearwood.info
Wed Sep 13 22:42:12 EDT 2017


On Wed, Sep 13, 2017 at 05:09:37PM +0200, Jason H wrote:

> The format of map seems off. Coming from JS, all the functions come 
> second. I think this approach is superior.

Obviously Javascript has got it wrong. map() applies the function to 
the given values, so the function comes first. That matches normal 
English word order:

* map function to values
* apply polish to boots   # not "apply boots from polish"
* spread butter on bread  # not "spread bread under butter"

Its hard to even write the opposite order in English:

map() takes the values and has the function applied to them

which is a completely unnatural way of speaking or thinking about it 
(in English).

I suggest you approach the Javascript developers and ask them to change 
the way they call map() to suit the way Python does it. After all, 
Python is the more popular language, and it is older too.


> Also, how are we to tell what supports map()?

Um... is this a trick question? Any function that takes at least one 
argument is usable with map().


> Any iterable should be able to map via:
> range(26).map(lambda x: chr(ord('a')+x)))

No, that would be silly. That means that every single iterable class is 
responsible for re-implementing map, instead of having a single 
implementation, namely the map() function.



-- 
Steve


More information about the Python-ideas mailing list