Re: [Python-ideas] Function composition (was no subject)
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
participants (6)
-
Andrew Barnert
-
Chris Angelico
-
Douglas La Rocca
-
Koos Zevenhoven
-
Ron Adam
-
Steven D'Aprano