Allow specifying list of functions to `map`

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())

On 2014-03-30 18:59, Ram Rachum wrote:
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 think that the problem there is that it's not obvious in what order they are applied. You could, for example, argue that map((f, g) x) should do map(f, map(g, x) rather than map(g, map(f, x)).

On Mon, Mar 31, 2014 at 4:59 AM, Ram Rachum ram.rachum@gmail.com wrote:
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())
stdout, stderr = map(lambda x: x.decode().strip(), popen.communicate())
Or:
stdout, stderr = popen.communicate() stdout = stdout.decode().strip() stderr = stderr.decode().strip()
Yes, the latter is a bit of duplication, but it's clear what's going on. (Obviously appropriate only where you know exactly how many elements there'll be, as in your example.)
ChrisA

On 2014-03-30 23:00, Chris Angelico wrote:
On Mon, Mar 31, 2014 at 4:59 AM, Ram Rachum ram.rachum@gmail.com wrote:
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())
stdout, stderr = map(lambda x: x.decode().strip(), popen.communicate())
Or:
stdout, stderr = popen.communicate() stdout = stdout.decode().strip() stderr = stderr.decode().strip()
Or:
stdout, stderr = (x.decode().strip() for x in popen.communicate())
for that matter.
Yes, the latter is a bit of duplication, but it's clear what's going on. (Obviously appropriate only where you know exactly how many elements there'll be, as in your example.)
participants (3)
-
Chris Angelico
-
MRAB
-
Ram Rachum