[Python-ideas] (no subject)
Ivan Levkivskyi
levkivskyi at gmail.com
Wed May 6 23:15:12 CEST 2015
This is one of the options, but in my opinion an operator (@ that I
propose) is clearer than a function
On 6 May 2015 at 20:44, Paul Moore <p.f.moore at gmail.com> wrote:
> On 6 May 2015 at 17:23, Ivan Levkivskyi <levkivskyi at gmail.com> wrote:
> > I should clarify why I would like to have the possibility to easily
> compose
> > functions.
> > I am a physicist (not a real programmer), and in my code I often compose
> > functions.
> >
> > To do this I need to write something like
> >
> > def new_func(x):
> > return f(g(h(x)))
> >
> > This means I see f(g(h())) quite often and I would prefer to see f @ g @
> h
> > instead.
>
> I appreciate that it's orthogonal to the proposal, but would a utility
> function like this be useful?
>
> def compose(*fns):
> def composed(x):
> for f in reversed(fns):
> x = f(x)
> return x
> return composed
>
> comp = compose(f, g, h)
> # comp(x) = f(g(h(x)))
>
> Paul
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20150506/219eadda/attachment.html>
More information about the Python-ideas
mailing list