[Python-ideas] Fw: Allow specifying list of functions to `map`

Andrew Barnert abarnert at yahoo.com
Mon Mar 31 00:53:31 CEST 2014


Sorry, google-grouped, so I'm not sure if this went out to the list or not; apologies if it's a dup…


From: Ram Rachum <ram.rachum at gmail.com>
Sent: Sunday, March 30, 2014 10:59 AM


> If `map` accepted a tuple for its first argument, things like this: 
> 
>     stdout, stderr = map(str.strip, map(bytes.decode, popen.communicate()))
> 
> Could become this: 
> 
>     stdout, stderr = map((bytes.decode, str.strip), popen.communicate())

I'm not sure whether to read that as returning:


    map(bytes.decode, x), map(str.strip, x)
    map(compose(bytes.decode, str.strip), x)
    map(rcompose(bytes.decode, str.strip), x)


None of the functional languages that Python borrowed map from have any of 
these, but that's because they all have compose as a builtin, or even an 
operator:

    map(bytes.decode @ str.strip, popen.communicate())

But I think in Python this is much more readable as an expression on each value 
rather than a higher-order function:

    (text.decode().strip() for text in popen.communicate())


Even in Haskell, a listcomp is often more readable than mapping a compose or 
other higher-order function, but that's much more true when you're using 
Python-style method calls.



More information about the Python-ideas mailing list