
Why python needs a compose function (but won't get it) - firephone
http://n-s-f.github.io/2016/12/05/python-compose.html
======
brightsize
He can have what he wants in the compile-to-python (2/3) language Coconut[1].
I'm using it and it's a joy.

    
    
      >>> def f1(x) = x * 2
      >>> def f2(x) = x * 3
      >>> newfunc = f1..f2
      >>> newfunc(1)
      6
    
      >>> 2 |> f1 |> f2
      12
    

and

    
    
      >>> [y for y in [1,2,3] |> map$(f1) |> map$(f2)]
      [6,12,18]
    

[1] [http://coconut-lang.org/](http://coconut-lang.org/)

------
polux-moon
Whats wrong with a self-made no sugar version in a library ? That's a one
liner and datascientists use lots of libs already.

output = compose(transform1, transform2, tranform3)(input) or output =
pipe(input)[transform1, transform2, tranform3] are too ugly ?

~~~
chris_7
> output = pipe(input)[transform1, transform2, tranform3]

This one seems abusive, I'm not much of a Python user, but it looks like it's
overloading indexing with a sequence (tuple) of functions to perform
composition?

The other one seems like the correct way to handle this, I don't understand
why it wasn't mentioned in the original post.

------
Cpoll
Could you get a similar effect by wrapping your data in a decorator that has
those methods? Then you just turn your transformation functions into methods
that work on the decorator.

``` data = transformable(data) data.some_transformation()
.another_transformation() .last_transformation() ```

Not ideal, of course.

------
tdb7893
Doing the same thing as function compositions in Python is very easy and
generally readable already. I don't think it would actually help readability
much because I agree with Guido that it would probably be really out of place
in the language.

