[Python-ideas] Function composition (was no subject)
Steven D'Aprano
steve at pearwood.info
Sun May 10 05:20:16 CEST 2015
On Sun, May 10, 2015 at 03:51:38AM +0300, Koos Zevenhoven wrote:
> Another way to deal with elementwise operations on iterables would be to
> make a small, mostly backwards compatible change in map:
>
> When map is called with just one argument, for instance map(square), it
> would return a function that takes iterables and maps them element-wise.
>
> Now it would be easier to use map in pipelines, for example:
>
> rms = sqrt @ mean @ map(square)
Or just use a tiny helper function:
def vectorise(func):
return partial(map, func)
rms = sqrt @ mean @ vectorise(square)
--
Steve
More information about the Python-ideas
mailing list