You can do :

I suggest this syntax:
> >>> map(.upper(), ['a', 'b', 'c'])
>

map(dot('upper'), 'a b c'.split())
map(dot('replace', 'x', 'y'), 'xo do ox'.split())

def dot(name, *args, **kwargs):
    return lambda self: getattr(self, name)(*args, **kwargs)


> This would also work for attributes:
> >>> map(.real, [1j, 2, 3+4j])
>

from operator import itemgetter
map(itergetter('real'), [...])

from operator import itemgetter as gatt
map(itergetter('real'), [...])


Also, check out my package funcoperators on pip for neat functional
programming syntaxes

https://pypi.org/project/funcoperators/
_______________________________________________
Python-ideas mailing list
[email protected]
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to