[Python-ideas] Function composition (was no subject)
Koos Zevenhoven
koos.zevenhoven at aalto.fi
Sun May 10 02:51:38 CEST 2015
On 10.5.2015 2:28, Ivan Levkivskyi wrote:
> functions. In other words I agree with Andrew that "elementwise" is a
> good match with compose, and what we really need is to "pipe" things
> that take a vector (or just an iterable) and return a vector (iterable).
>
> So that probably a good place (in a potential future) for compose
> would be not functools but itertools. But indeed a good place to test
> this would be Numpy.
>
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
values->map(square)->mean->sqrt()
Or if the change in map is not popular, there could be something like
functools.mapper(func) that does that. Or even something more crazy,
like square.map(seq), so that square.map could be used in pipelines.
-- Koos
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20150510/e8a4a603/attachment.html>
More information about the Python-ideas
mailing list